sorting refactoring