calculateDistance fixed