added scope-aware reference resolution