Previous loop detector was not correct.  You know that you've found a loop when you encounter the same node while recursively descending through the tree.