In upholding a temporary restraining order on President Trump’s travel ban, the Ninth U.S. Circuit Court of Appeals has delivered a much-needed reminder to the administration that no one in this country is above the law, and that its system of checks and balances remains in effect.

The most significant element in the court’s decision may prove to be its strong rejection of the president’s assertion that his executive order was “unreviewable.” The three-judge panel, in its unanimous ruling, wrote that “There is no precedent to support this claimed unreviewability, which runs contrary to the fundamental structure of our constitutional democracy.”

Still just weeks into his presidency, Trump appears to be struggling with the notion that he cannot run the United States as a CEO whose orders are inviolable. The travel ban executive order was rushed out in haphazard fashion, bypassing the usual protocols that provide the underlying rationale for a decision and scope out potential weak spots. Former Acting Attorney General Sally Yates had warned that the ban would not pass legal muster. Instead of heeding that warning, Trump, in a fit of pique, fired her.

Upon learning of the appeals court’s ruling, Trump indulged in another embarrassing tweet-tantrum and said the judges’ ruling was political. There is simply no basis for such an accusation, and the president should be more mindful of openly denigrating one of this nation’s most valued institutions. The three judges, it should be noted, represent appointments by Presidents Jimmy Carter, George W. Bush and Barack Obama.

Any new president deserves a chance to chart the course he thinks voters endorsed. But learning from mistakes is a necessary element of sound leadership. Instead of bashing the judges, or appealing this sloppily devised order to the Supreme Court, Trump would be better advised to take a new, more measured, more focused and better-researched swing at tightening security for would-be entrants to this country. He has most of his Cabinet in place now, and they can provide sound advice. If a new, better-crafted order involves a temporary travel ban, the law indeed gives the president wide latitude when it comes to immigration and national security measures.

But, as the circuit court ruling shows, even the president is subject to review, and thank goodness for that. There was little justification for barring the entry of legal green card holders, or Iraqis who, because of their life-risking efforts to aid the U.S. military, had been promised asylum. Scientists? Doctors? Any net that sweeps in such established professionals is too broad.

The court did not definitively rule on the merits of the challenge to the travel ban. And while its decision was frank in places, it also was restrained and limited. It is focused mainly on the order’s failing to provide procedural rights to permanent legal residents, reserving judgment on more sweeping claims like those about religious discrimination. That suggests that a more narrow and carefully implemented limit on new refugee admissions might well pass legal muster — whatever one thinks of it as policy.

Minnesota Attorney General Lori Swanson, who joined with Washington state in filing the lawsuit against the ban, said as much in her statement regarding the decision. “A more deliberate approach by the administration could have avoided this litigation,” Swanson said. “The executive order was haphazard in its approach and rollout, not properly vetted by Congress of the federal departments of State, Justice, Homeland Security or Defense, and created needless chaos for children, families, students, physicians, businesses and travelers.”

Minnesotans should be proud of the critical role this state played in staying such a ban. States showed they can function as a brake against a heedless federal government that is reaching beyond the law. That should provide some reassurance to Americans as this still very young administration finds its footing.