Judge Christina Reiss ruled Tuesday that a U.S. customs officer improperly canceled the visa of Kseniia Petrova, a Russian-born scientist and Harvard University researcher accused of smuggling frog embryos into the United States, saying the agency acted beyond its authority.

In her written ruling, Reiss said Customs and Border Protection officers have limited authority to cancel visas and cannot do so for suspected smuggling of biological samples. Reiss said Petrova’s visa cancellation was “arbitrary and capricious,” according to the opinion.

“The undisputed facts reveal that Ms. Petrova’s visa was impermissibly canceled because of the frog embryo samples and for no other reason,” Reiss wrote in the opinion.

A U.S. Department of Homeland Security spokesperson said in an emailed statement Wednesday that Petrova was “lawfully detained after lying to federal officers about carrying substances into the country.” The spokesperson also said President Donald Trump’s administration was committed to “restoring the rule of law and common sense to our immigration system,” adding that the department includes Customs and Border Protection.

Petrova’s case began after she returned from a vacation in France and stopped at a laboratory there that specialized in splicing superfine sections of frog embryos. Prosecutors allege she brought a package of samples for research when she arrived at Boston Logan International Airport, where she was questioned about the samples at a customs checkpoint.

After an interrogation, Petrova was told her visa was being canceled, and she was briefly detained by immigration officials in Vermont. She later was sent to a U.S. Immigration and Customs Enforcement facility in Louisiana, where she filed a petition seeking her release.

Petrova told The Associated Press in an interview last year that she did not realize the samples needed to be declared and that she was not trying to sneak anything into the country. Her attorney, Gregory Romanovsky, said Petrova had returned to work at Harvard after successfully petitioning a court for the right to do so in January.

Romanovsky said Tuesday’s decision was “an important step toward ‘correcting what should never have happened in the first place,’” in a statement.

The court ruling drew attention from the scientific community, with some researchers concerned the dispute could affect recruiting and retaining foreign scientists at U.S. universities.