Refactored controller