extracting logic out of the controller