bug fix on path finding algorithm