refactored controller and templates