Cleaner version of dist_calc.pl