First pass at reimplementing templating.
Tidying up the templating rework.