Fixing Modulefile and template variable scope