The Justice Department on Thursday agreed to withdraw grand jury subpoenas seeking testimony and records from New York Times reporters and their family members after a federal judge repeatedly questioned why prosecutors had issued the subpoenas before pursuing alternative investigative steps.

During a hearing Thursday before U.S. District Judge Arun Subramanian in Manhattan, prosecutor Sean Buckley initially resisted withdrawing the subpoenas, arguing that they should instead be held in abeyance so the government could preserve the records in case they were needed later.

But Subramanian repeatedly pressed Buckley on the distinction, noting that the government could quash the subpoenas and return to court later with new applications if justified.

“Doesn’t the law indicate that subpoenas are the last step? Not the first step but the last step?” Subramanian repeatedly asked.

“Subpoenas issued to reporters for their records, they are not the first thing you do; they are the last thing you do,” the judge added, citing the “profound First Amendment issues” involved.

Buckley acknowledged that the government had mistakenly obtained phone records associated with the mother and spouses of reporters after a public-source database incorrectly linked the numbers to the subject of the investigation.

“That was an error,” Buckley said. “It was a mistake; it was not in furtherance of the investigation.”

The Trump administration initially subpoenaed a group of New York Times reporters a few weeks ago after the paper published stories about security concerns surrounding the new Air Force One, which was donated by Qatar.

The stories came out after President Donald Trump flew home from an international trip to Turkey on the old Air Force One, prompting questions about why the new aircraft wasn’t used.

The Times journalists, using anonymous sources, reported that the Secret Service urged the president to fly home on the old presidential aircraft after a resumption of hostilities with Iran, partially because the new Air Force One isn’t equipped with anti-missile capabilities.

The paper at the time said that some of the subpoenas were issued to reporters by federal agents who showed up at their homes and that the subpoenas sought information about who leaked details about the security concerns to the Times reporters.

In a statement, David McGraw, the Times’ senior vice president and deputy general counsel, called the Justice Department’s decision to drop the subpoenas, “an important affirmation of our country’s commitment to a free press.”

He added, “We are pleased that the government finally conceded that the subpoenas violated the law, but they should never have been issued in the first place. The Times and our journalists will continue to report and seek the truth without fear or favor. We will not be deterred in the face of tactics like these.”

A Justice Department spokesperson blamed Subramanian in a statement, saying, “This judge threatened our attorneys with sanctions unless subpoenas were withdrawn, and blocked us from presenting the meticulous process of this investigation. The grand jury has a right to hear testimony from all material witnesses in a federal criminal investigation. This judge’s conduct overrides clear longstanding principles and common sense—blocking the grand jury from receiving core evidence in a national security investigation.”They added that the investigation remains ongoing.

Buckley on Thursday said the reporters are not the targets of the investigation, the leakers are, and that the government is prepared to immunize them to compel their testimony.

Subramanian also warned that the government’s incorrect and incomplete court submissions could lead to sanctions, saying that in a civil case he would normally require the parties to show cause why sanctions should not be imposed for misstatements to the court. Buckley called the errors inadvertent.

The government ultimately agreed to withdraw the subpoenas and pursue other investigative steps, while reserving the possibility of seeking new subpoenas in the future.

New York Times attorney David O’Neil said the newspaper fundamentally disagreed with the government’s argument that holding the subpoenas in abeyance was equivalent to withdrawing them.

“There are fundamental First Amendment issues, the record is replete with bad faith,” O’Neil said, adding that the subpoenas had already had a chilling effect on the reporters.

“Given the chill these subpoenas have already produced, it is clear that having these subpoenas out there has been damaging to the reporters,” he said.

O’Neil also emphasized that the government had acted unilaterally in issuing the subpoenas and seeking the phone records.

Subramanian ended the hearing on a light note, asking prosecutors if someone is at home watching the new movie starring Hugh Jackman, “Sheep Detectives.”

“We are not going to have FBI agents showing up at the door?” the judge asked after referencing the movie, with Justice Department attorneys promising that won’t be happening.