Fix Tree memory leaks, Optimize hot spots