adding two pass scope visiting to handle forward references