Updated sorting algorithm.