Fix the problem with template variables getting encoded prematurely

Fixes #2