Fixing JS error when node is not found in the tree