Refactor template files