finished writing functions for tree.c