env-setup script refactored