BUG: fix logic in shortest_path