Further work on the templates
First version of the templating feature complete

- still needs some refinement, but it's feature-complete