[BUGFIX] Change variable scopes in template