Fix division by zero error when mean_distance is zero
Whitespace and formatting