Implement category sorting.