refactored controller