update to current templating

Hi Rob,
please merge these changes to work with the current templating...
I also added a fix to templating as there was a bug in the compiler...

Tobias