error fix in distance calculations