Refactored templates to use DocumentFragment