Refactor templates