added the tree functions and tests