Move logic out of the controller.