updating the sort function