Removed duplicated code from controllers.
Extracted sorter class.