Refactored code in controllers.