add function for tree