Refactored update_env(). Cleanups.