corrected distance calculation