Fixed the tree hierarchy
cleaned up some code