added pathIndex logic