patch from Harry Li contributed code.