added maxDist calculation, but it kinda blows