Fixed the "not-so-shortest-path" bug (thanks to Cédric Jules)