2D tree building