Topology fix shortest path

This PR is a big fix to play with shortest path function.