Optimizations in tree generator