fix sort function