Recursion/invalid node tree check

Stops never ending recursion caused by invalid trees