Implemented sorting.