Refactor template script.