fixes for the distance calculations