Fix to template variable. See comment in code for details. Thanks to Alex G. for the catch.