President Donald Trump’s lawsuit against the Internal Revenue Service over his leaked tax returns was filed for an “improper purpose,” a judge said Monday as she referred one of his lawyers for potential disciplinary action and characterized the $10 billion complaint as an exercise in self-dealing.

U.S. District Judge Kathleen Williams accused Trump and his lawyers in a scathing ruling of having manipulated the court system when he sued a federal agency under his control, bypassing a requirement that parties in a lawsuit must have adverse interests. The lawsuit ended in a settlement that granted the president immunity from tax audits and established a $1.776 billion fund to compensate Trump allies who believe they have been unjustly persecuted.

The judge stopped short of explicitly voiding the deal shielding Trump from tax scrutiny but said the government cannot claim in official proceedings that the agreement was the result of a legitimate legal process.

“Whether Executive Branch actors can privately agree to give themselves and their former clients blanket immunities and billions of dollars in tax monies for legally undefined grievances was never an issue advanced to this Court,” said Williams, an appointee of President Barack Obama. “The question is whether the Parties could do so by claiming to be adverse and engaging the legitimacy of a court proceeding. The answer is a resounding ‘no.’”