Instead of using != nothing try using the Isvalid node or isvalid boolean into you branch.
Edit: Actually casting should take care of the valid check by itself (if im not mistaken), so you should be able to remove both of the != checks.
Hope that helps.