refactor calculation of shortest path tree.