a shortest path function that works-ish