Improved preparation of template variables