improved get_env() method