The U.S. Supreme Court is trying to clean up the legal mess that is the Trump administration’s attempt to restrict immigration for national security reasons. Better known as the travel ban, its versions one and two have been bouncing around federal courts for five months.

One of President Donald Trump’s first decisions was a dramatic 90-day emergency ban on all travel from certain Muslim nations to protect the nation from terrorism. It’s now unlikely to get resolved until the second year of Trump’s presidency.

The justices yesterday tried to give some immediate clarity to U.S. policy until it rules in two cases presenting broader challenges to the travel ban as an unconstitutional discrimination against religion because it unfairly targets Muslims. Lower courts dealt with the flaws in the poorly drafted and overly broad bans by freezing their implementation until the higher court could take a look.

So in coming up with its placeholder ruling, the court tried to find some balance in the competing claims, and added a little common sense. The temporary ban will not apply to visa seekers who have strong, documented connections to the United States, such as those wanting to visit family members, students admitted or enrolled in American schools or workers who have accepted employment here. Those situations describe most of the visa applications, a win for those groups seeking to overturn the ban.

However, the court applied the ban to travelers from six majority Muslim nations who have no ties to the United States, such as those seeking tourist visas, or refugees, a group that represents 1 percent of total applicants. So Trump’s tweet “very grateful for the 9-0 decision” isn’t quite accurate. The administration won a limited victory.

In its unsigned opinion, the court made clear that the president has broad powers to act in the interest of national security. He does. What the court still has to decide is whether he went too far.