Fixed tree downloads
Cleaned up a lot of the code, got rid of some bugs