Handle corner cases with shortest_path method.
Make minor style change.