Sorting algorithm updated