Refactor shortest paths