refactor sorter to improve quality