Refactoring sorting order