Refactored logic into the model and out of the controller