Refactored segment and environment.