Made some fixes to the tree sorting

The sorting now looks better when converted to a String.
Functionality for sorting is improved.