A federal judge has ordered the Department of Homeland Security to halt certain investigative actions in its search for noncitizen voters, writing that the department’s efforts are based on erroneous data that includes U.S. citizens legally allowed to vote. Judge Araceli Martínez-Olguín wrote in the order that DHS data alleging hundreds of thousands of potential illegal voters “is widely known to inadvertently include U.S. citizens” and “leaves citizens fearful that their names will be erroneously included among the hundreds of thousands identified for investigation.” The judge’s order specifically limits actions DHS takes in the field to investigate noncitizen voting, such as interviews, and says DHS cannot take those actions if it believes the person being targeted could be a U.S. citizen. However, the order, which covers California, Connecticut, Georgia, Missouri, Nevada, New York, Pennsylvania, Washington and Wisconsin, does not take effect until Friday afternoon, giving the Trump administration time to appeal. Once it goes into effect, it will last until after the midterm elections. DHS has been a driving force behind the administration’s efforts to bolster President Donald Trump’s baseless claims of widespread voter fraud by noncitizens, aggressively expanding its efforts to investigate the issue. The new ruling, although limited in scope, marks a notable retreat from the agency’s approach. CNN has reached out to DHS for comment. “This order is a serious protection: the current policy targets known naturalized citizens,” Beau Tremitiere, an attorney with Protect Democracy, a legal organization representing the groups that brought the case, told CNN. “Such operations are prohibited. And this order should force DHS to stop assuming that many others are viable targets when there is evidence of citizenship.” Martínez-Olguín wrote in his order that “what is at stake here is the reliance on admittedly flawed and incomplete data to create a list of people for HSI to interview in the months leading up to an election.” in the upcoming midterm elections, as they may be included on the extensive and flawed lists that DHS has created. “The public’s interest in secure elections, free from interference or intimidation, far exceeds defendants’ purported interest in combating illegal voting by non-U.S. citizens,” the judge wrote Wednesday.