Reorder tree building code.