externalized globals

I should probably rewrite to avoid relying on global objects so
extensively at some point.