fix loop condition in _allDistMargin