fix distance calculation bug