fix bug sort function