fix generation of scoping rules for named and external scopes