adding tree functions and tests