support for module-level globals and some cleanups