refactor sort method