treebuilder: insert sorted

This should be more efficient than inserting and then sorting.