Added sort functionality within display function