sort the tree better