Fix 2 bugs in the routing distance algorithms