Fix bugs in the findObstacle() function.