Refactored HeadlessEnvironment