ScopeNum -> ScopeId and make a type out of Scopeid.
Environment lookup nows uses scope to disambiguate variables with the same name. More tweaks are needed, but this is a great start.