updated to average distances
updated with mean distances