Changed to use sort in place.