Some refactoring needed to simplify templates. refs #421