Bug fix in sorting.