The U.S. Supreme Court ruled on Tuesday that a controversial travel ban affecting citizens of Libya and Somalia hoping to enter the U.S. will stand, despite legal challenges dating to the first days of President Donald Trump’s administration.

The 5-4 ruling keeps in place a reworked version of the ban that was introduced in September. It originally included travelers from Chad, but those restrictions were lifted in April after the U.S. determined that Chadian officials had “sufficiently improved” the country’s performance on passport and border controls.

The rules developed by the U.S. Department of Homeland Security, working with the Department of State, base the U.S. decisions on specific criteria, all centered in a nation’s ability to effectively manage and share information about citizen identity and national security risk. The U.S. evaluation also considers whether a country is a “known or potential terrorist safe haven” overall, and whether or not a nation cooperates in accepting its citizens when they are removed from the U.S.

The criteria shifted the emphasis away from identification as Muslim-majority countries, which was seen as a violation of U.S. immigration law and constitutional protections against religious discrimination.

While Chad and Sudan were removed from the list, the ban remains in place for Libya and Somalia, despite Mogadishu’s security cooperation with the U.S. Other countries affected include Venezuela, North Korea, Syria, Yemen, and Iran.

Since Trump took office in January 2016, U.S. foreign policy has reflected the more protectionist and security-focused values of the administration that followed former president Barack Obama. The Supreme Court decision comes at a time of heightened debate in the U.S. over immigration policy.