changed the sort function