refactored where sort() method is called