Major phpmd related refactoring of TemplateController and many related files