fixed edge insertion function and path finding algorithm.