calculateDistance function added