extract some of the logic out of the controller