Refactoring Controllers and templates