Template controller refactoring