Small fix for distance calculation