Perform final sorting of the dataset.