Refactored getEnvironment