refactor sorter creation logic