refactoring to support parallel template generation