Updating the tree
Improved code