Massive refactor to make subclassing and overriding templates easier.