fixed math error while calculating distance