fixes in distance calculation
merge