Added TTree caching, cleaned up code