freeTree function written and not tested