Refactoring for supporting multiple templates