Finished refactoring to decouple relationships between templates and template defs. refs #500