move to proper place
best-distance implementation