Refactor tpl files