make the sort function correct