refactor sorter