refactored controller and templates
refactored controller and templates