Some refactorings to support global templates. refs #418