make 'new_env' a free function