Remove recursion and isolate traversal code into getNodeParent().