Added a cleanup function to the tree