How many Iranian terrorists have staged attacks in the United States? How many Sudanese? Or Iraqis or Syrians? Or Yemenis? Or Libyans? They are, of course, trick questions as the answer is none. Pakistanis, yes, central Asians, yes, a Somali, a couple of Egyptians and lots and lots of Saudi Arabians. Somalia is on the list of countries now completely blocked for travel to the U.S., but citizens of the other countries have never staged a terrorist attack and are being restricted anyway. And Pakistan and Saudi Arabia, where Americans are perceived extremely negatively and where most terrorists have actually come from, are not on the list.

Donald Trump issued on Thursday an executive order, “Protecting the Nation from Foreign Terrorist Entry into the United States.” Some critics are claiming that several of the Muslim countries exempted are where Donald Trump has investments, but I don’t think that is in any way true. Trump raised the issue of immigration and refugee security back in the summer, and his views have been consistent. I rather believe that the current plan is a continuation of reactionary and ill-conceived policies that have been hanging around since 9/11 that see Muslim states as definable through a process that is more political than driven by the reality of where terrorism comes from. The seven countries in question were already classified as “countries of concern” under President Barack Obama and subjected to additional scrutiny. Congress also produced a bill last year that proposed stopping all refugee intake from Syria and Iraq until it could be certified that the new arrivals pose no security threat. The bill did not become law, but it reflected broad sentiment in the legislature that not enough was being done to determine just exactly whom we were letting into the country.

Blocking the entry of people by nationality, even if they have satisfied all normal requirements for visa issuance, might well be illegal under current immigration law, and the executive order is currently being challenged in the courts. And some are also noting that if it truly were a question of national security based on discernible facts, Saudis and Pakistanis would be blocked and subject to intensive secondary review for visa issuance, not Iranians or Sudanese. And what about the omission of Afghanistan, where numerous Americans have been killed by Afghans, though admittedly there have been no attacks generated against the United States itself?

And the executive order truly lacked any touch of common decency, which might have been considered without weakening its intent. It could and should have permitted visa and green-card holders already in transit or arriving at U.S. ports of entry to be godfathered in. The grief experienced by divided families and loved ones ricocheting between airports is just not acceptable and was widely played in the media worldwide. Only on Sunday did the administration change course and say green-card holders would not be barred.

All of which is not intended to suggest that the executive order is completely wrong-headed. The countries in question, with the exception of Sudan and Iran (included because they are, for reasons that basically make no sense, labeled state sponsors of terrorism), do indeed have major radicalization problems, as described in the State Department’s annual Country Reports on Terrorism. It is quite sensible to block travel by citizens of those countries until one can establish procedures to make sure that militants are not being admitted to the U.S., because embassies overseas have only limited ability to vet prospective visitors or immigrants. To be sure, the Obama administration has insisted that it applies an extreme vetting process to would-be refugees, asylum seekers, immigrants, and tourists, but it has failed to provide any details of how the system actually works.

It should be assumed that groups like ISIS and al-Qaeda would be delighted to infiltrate refugee, immigrant, and tourist travel movements into Western Europe and the U.S., which makes American embassies and consulates overseas the choke points for keeping potential terrorists out. Having myself worked the visa lines in consulates overseas, I understand just how difficult it is to be fair to honest travelers while weeding out those whose intentions are less honorable. At the consulate, an initial screening based on name and birth date determines whether an applicant is on any no-fly or terrorism-associate lists. Anyone coming up is automatically denied, but the lists include a great deal of inaccurate information, so they probably “catch” more innocent people than they do actual would-be terrorists. Individuals who have traveled to Iran, Iraq, Sudan, or Syria since 2011, or who are citizens of those countries, are also selected out for additional review.

For visitors who pass the initial screening and who do not come from one of the 38 “visa waiver” countries, mostly in Europe, the next step is the application for a visitor’s visa, called a B-2. At that point, the consulate’s objective is to determine whether the potential traveler has a good reason to visit the U.S., has the resources to pay for the trip, and is likely to return home before the visa expires. The process is document-driven, with the applicants presenting evidence of bank accounts, employment, family ties, and equity like homeownership.

Whether an applicant hates America or not is inevitably hard to determine from documents. In some countries, the documentary evidence can be supplemented by police reports if the local government is cooperative. Some consulates employ investigators, generally ex-policemen, who are able to examine public records if there is any doubt about an applicant’s profile or intentions, but most governments do not permit access to official documents. Recently, background investigations have sometimes been supplemented by an examination of the applicant’s presence on the internet to determine whether he or she is frequenting militant sites or discussing political issues online. If the visa applicant is seeking to become a U.S. resident, the process is, of course, much more rigorous and takes much longer.

Both travel and immigrant visas are nevertheless a somewhat subjective process and as they are both document-driven and reliant on what a potential traveler says in his or her interview. In many places, official documents are the weak link, as they are easy to forge or can even be obtained in genuine form from corrupt bureaucrats. If one is unable to go the source of the document for verification, papers submitted in support of a visa application are frequently impossible to authenticate. So what does one do when applicants from countries in the throes of civil war—like Iraq, Syria, Libya, or Yemen—show up at a visa window, some of them with no documents at all? Or when such applicants constitute not a trickle but a flood applying for asylum or refugee status? It gets complicated, and Trump has a point in saying we should deny entry to all of them until procedures can be established for making those judgments in a more coherent fashion.

I personally believe that the United States has a moral obligation to accept a considerable number of refugees and asylum seekers from countries that it has intervened militarily in. Washington is also a signatory to the United Nations-administered agreements to resettle refugees, producing another steady stream of immigrants that Trump is currently blocking. Much of the refugee background vetting is carried out by the UN in a not-completely-transparent fashion, and the resettlement of those who are accepted in various places is done by quota—with the U.S. being the largest recipient country, expected to receive about 100,000 in 2017, a number that Trump intends to cut roughly in half.

But the current refugee policy unfortunately means accepting many who have been on the receiving end of U.S. military interventions. Some inevitably harbor thoughts of revenge against the West and the U.S. in particular, meaning that Washington has been taking in many people who have good reason to dislike the United States. This results in a home-grown problem that manifests itself in the courts, where most of those convicted in terrorism-related cases in the U.S. are foreign-born. America’s 100,000 Somali refugees have been a particular problem, with many returning home to join the al-Qaeda-affiliated al-Shabaab.

There are a number of other issues that the executive order does not consider. Many of the most radicalized Muslims now carry European passports, and though some already receive additional scrutiny because of where they were born, they are able to travel relatively freely. Also, the executive order’s singling out of “religious minority” refugees for favorable treatment and the repeated use of expressions like “radical Islamic terrorism” will give ammunition to those who already believe that the “War on Terror” is actually a war on Islam. Finally, banning travel from certain countries invites reciprocity and other nations that are outraged by Trump’s move will require visas and screening for American travelers.

The real issue that Trump is and should be addressing is the federal government’s inability to vet visa applicants, immigrants, and refugees to a level that could be considered sufficient from a national-security perspective, a failure that has led some conservatives to complain that White House policy is to “invade the world, invite the world.” Trump’s demands to block many visitors and would-be residents might seem, and in some respects surely is, an overreaction, and it could have benefited from some fine-tuning to make the package less humiliating for travelers and more palatable for a global audience. But until a broken immigration system is fixed, he is more right than wrong.

Philip Giraldi, a former CIA officer, is executive director of the Council for the National Interest. This article is adapted in part from one he wrote last June.