More rigiourous elimination of undef in path and environment