(This January 31 story corrects date of original court ruling in paragraph two)

WASHINGTON (Reuters) - A U.S. appeals court on Wednesday upheld the structure of the U.S. Consumer Financial Protection Bureau, determining it is constitutional to bar the president from firing its director at will, even as the Trump administration works to weaken the regulator.

Wednesday’s ruling overturns an October 2016 decision that had given presidents the power of dismissal over a CFPB director and marks the latest development in a complicated fight over leadership of the agency, which was established to crack down on predatory financial practices after the 2007-2009 financial crisis.

The ruling from the Court of Appeals for the District of Columbia is part of a broader fight over the agency’s structure, and comes amid a separate, more immediate controversy that emerged after President Donald Trump appointed Mick Mulvaney, an agency critic who also is director of the Office of Management and Budget, as its temporary head in November.

The CFPB had appealed the 2016 court decision that gave the president the power to fire the agency’s director without proof of serious misconduct. The fight over the agency’s structure is part of a continuing lawsuit between the agency and a mortgage servicer, PHH Corp.

“Congress’s decision to provide the CFPB director a degree of insulation reflects its permissible judgment that civil regulation of consumer financial protection should be kept one step removed from political winds and presidential will,” the court wrote.

Republican critics of the CFPB, arguing it is too powerful, were quick to call for the case to head to the Supreme Court. PHH was noncommittal in a statement and a company spokesman said the firm is evaluating its next steps.

A CFPB representative said the agency also was analyzing the decision.

Wednesday’s ruling is separate from a pending case on the leadership of the agency in which the CFPB’s deputy director, Leandra English, is suing to bar Mulvaney from heading the agency.

The original ruling by a three-judge panel on the D.C. Circuit Court threatened to upend the CFPB, which was created as part of the 2010 Dodd-Frank financial reform law. There, judges ruled that it was unconstitutional to grant a single director, serving a five-year term, protection from presidential removal.

Wednesday’s decision did have good news for PHH with the court reinstating an earlier ruling throwing out the $109 million fine the CFPB levied against PHH, which was the catalyst for the lawsuit. Judges previously determined the CFPB overstepped its bounds in assessing that fine.

In its statement, PHH said that decision was “an important and gratifying outcome.”

Mulvaney’s appointment to the job set off a controversy when English, chosen by outgoing CFPB director Richard Cordray as his replacement, filed suit to bar Mulvaney from taking the job. A federal judge ruled against English in November, leading to her appeal.