Inline buildTree(), annotate tree building functions