WIP: optimization of the tree construction procedure