Implemented a stable heuristic for shortening paths.