fixed min_distance bug