Introduce abstractions for global scopes.

And various bonus cleanups.