bug fix distance calculation