refactor environment-related code