calculate distance properly