refactoring sorting