Template modularization and fixups