Factor environment into separate class with support for global objects