correct path calculation end condition