Updated sort functionality