tree building optimised