fix A* algorithm