improve shortest path method