Adding code to build the tree and check if node exists before adding to tree.