Moving the logic from Controller to Model