Refactoring templates to reduce duplication