sorter refactored