Fixing maxdist if