Refactor template