A federal judge invalidated part of North Carolina elections law that allows one voter to challenge another’s residency, a provision that activist groups used to scrub thousands of names from rolls ahead of the 2016 elections.

U.S. District Judge Loretta Biggs said in an order signed Wednesday that the residency challenges are pre-empted by the 1993 federal “motor voter” law aimed at expanding voting opportunities.

The National Voter Registration Act “encourages the participation of qualified voters in federal elections by mandating certain procedures designed to reduce the risk that a voter’s registration might be erroneously canceled. Defendants’ conduct contravened these procedures,” Biggs wrote.

Biggs had ordered days before the 2016 elections that Cumberland, Moore and Beaufort counties restore thousands of canceled voter registrations. She acted after the NAACP and others sued, alleging the purge of voter rolls disproportionately targeted blacks. Biggs concluded then that the three counties had purged between 3,500 and 4,000 voters from registration rolls since August 2016.

The people who had challenged valid residency of voters filing challenges in Cumberland and Moore counties were volunteers with the Voter Integrity Project. The group’s North Carolina director, Jay Delancy, said it was part of an effort to reduce the potential for voter fraud.

“We followed North Carolina law scrupulously in filing more than 6,000 individualized voter challenges in 2016 and the local election boards acted properly in sustaining those challenges,” he said Wednesday. He said his group would ask state legislators to revise the law “to empower private citizens wishing to detect and challenge illegal voters.”

Moore County Attorney Misty Leland said her county’s elections board had done as the state law required and the state elections board directed. Attorneys for Beaufort and Cumberland counties did not respond to invitations to comment.

In most cases cited by the NAACP lawsuit, residency challenges followed after mail to a voter was returned as undeliverable. County elections boards can accept returned mail as evidence that the voter doesn’t live there. That resulted in a hearing at which challengers presented evidence, according to a state legal filing. If local officials found probable cause, the challenged voter was given notice of a subsequent hearing. A voter who doesn’t rebut the evidence can be removed.

“By purging dozens and sometimes hundreds of voters at a time based on returned postcards, the state was disenfranchising eligible voters and violating federal law. This ruling ensures an end to this illegal practice,” plaintiff’s attorney Leah Kang wrote in an email.