Texas officials agreed Friday to end a controversial review of state voter rolls targeting noncitizens after it was revealed the project was based on flawed data. The agreement came as part of a settlement to end multiple federal lawsuits filed on behalf of civil rights groups and naturalized citizens.

A federal judge in February temporarily ordered the state not to cancel anyone’s voter registration based on the data and criticized the state’s “ham-handed” effort to identify noncitizens.

Friday’s settlement permanently blocks the state from using the information it made public in January to cancel anyone’s voter registration.

Texas officials announced in January that nearly 100,000 noncitizens could be on state voter rolls and that 58,000 of them may have voted in one or more election. But after those claims got widespread attention, including from President Donald Trump, officials acknowledged the numbers were based on flawed data.

Acting Texas Secretary of State David Whitley (R) compared voter registration information to records from the Department of Public Safety and flagged instances in which a registered voter had also indicated they were a noncitizen when they applied for a driver’s license. Whitley’s office advised election officials they could investigate those voters and cancel their registrations if they confirmed they were, in fact, noncitizens.

Civil rights groups quickly pointed out the data likely included people who were noncitizens when they applied for driver’s licenses but then later registered to vote after becoming naturalized citizens. At least 20,000 people appear to have been incorrectly placed on the list.

Under Friday’s agreement, Texas must completely rescind the secretary of state’s election advisory and instruct local officials to immediately reinstate any voter registrations that were canceled as part of the process.

The Texas Secretary of State’s office also agreed to rework the way it compares voter registration records with information from the Department of Public Safety. Under the agreement, officials say they will only flag individuals who have registered to vote and then gone on to say they are a noncitizen when getting a driver’s license. The Texas Secretary of State’s office also agreed to regularly update lawyers for the civil rights groups on how many people have their voting status flagged for review.

The state also agreed to pay $450,000 in legal fees as part of the settlement.

“Three months after the State released a discriminatory and flawed voter purge list, they have finally agreed to completely withdraw the Advisory that risked throwing tens of thousands of potentially eligible voters off the rolls,” said Beth Stevens, voting rights legal director with the Texas Civil Rights Project, one of the groups that brought the lawsuit, in a statement.

“State officials have wasted hundreds of thousands of dollars and struck fear and confusion into thousands of voters in order to pursue their voter suppression agenda,” Stevens said.

The settlement represents a “profound retreat” from the original program Texas officials were using, said Danielle Lang, an attorney at Campaign Legal Center who also represented some of the plaintiffs in the suit.

Whitley said in a statement that the agreement would allow Texas to maintain accurate lists while making sure naturalized U.S. citizens aren’t removed from the rolls.

“I will continue to work with all stakeholders in the election community to ensure this process is conducted in a manner that holds my office accountable and protects the voting rights of eligible Texans,” he said.