Refactors template()