Fixed a distance calculation bug