Much better performance for sorting.

This was accomplished by temporarily collapsing all trees during the sort.

Also simplified sort function since we can assume strings always.

Fixes a bug that was causing results to be truncated after sorting on windows. Closes #181.