Refactored template code to allow for more template inheritance