Changed the sorting algorithm