fixing the distance calculation