More cleanups

Here's a few cleanups. Most of it reduces dependencies on register_globals, either by looking up variables explicitly, or by explicitly importing selected variables.