Refactored controller and model