Optimize trees