Changed sorting algorithm