refactored the sorter.