Fix sort functionality