Environment: Refactoring and cleanup