Major template refactor