add stop flag and special case for path len == 0