As the shock fades, the dead are buried and their lives remembered, the focus is on how Omar Mateen could have been stopped before he took the lives of 49 people in a Florida nightclub.

The answer, as with other recent massacres, seems to be that this mass shooting, the largest in our history, might have been prevented if our national security apparatus were more coordinated and effective. This might require a better calibration of the balance between our civil liberties and security. How we do that is the challenge.

The Orlando killings are now central to the 2016 presidential election. Donald Trump on Monday called for a shut-off of immigration from countries where terrorism is a threat. But civilians from those places face devastating humanitarian crises, and such a test of religion and nationality is out of touch with our nation’s values.

Hillary Clinton came closer to the mark, pledging in a speech to make the targeting of lone wolves a top priority and pointing out that Mateen already had been on the FBI’s radar. But she also said the nation needs “more resources for this fight.” That’s an easy sop to worried voters, but hundreds of billions of dollars are already spent on law enforcement and security practices, much of it poorly.

What’s needed is competence. Mateen, a New York-born 29-year-old whose parents came from Afghanistan, was investigated by the FBI in 2013 after he made comments that co-workers believed were sympathetic to terrorists. The FBI determined he hadn’t broken any laws.

He was again investigated in 2014 because he had contact with an American who later conducted a suicide bombing in Syria. The FBI, however, concluded he had only minimal contact with the man. Mateen was put on a terrorist watch list, then removed.

advertisement | advertise on newsday

Even if he had been on such a list, however, he still could have bought the handgun and semi-automatic rifle he purchased in the past two weeks that were used in the shooting. He was a citizen and had no criminal record. But if the purchases had raised a red flag, and led to FBI surveillance, an examination of his associates or his use of social media, these deaths might have been prevented.

That is too often the case. Previous mass killers have tripped law enforcement alarms and sent signals to friends, co-workers or family. Dylann Roof, accused of killing nine black churchgoers in South Carolina last June, was charged with drug possession before he bought his handgun. That arrest should have nixed the sale, but his background check wasn’t completed in a timely manner, and Roof got the weapon.

Tamerlan Tsarnaev, one of the two brothers responsible for the Boston Marathon bombing in 2013, was reported to the U.S. government to be a potentially violent Islamic radical twice in the two years before his attack, and he was added to a list of potential threats. He was questioned by the FBI, but went to Dagestan, a hotbed of Islamic terrorism in Russia, to train as a terrorist, and he re-entered the United States without being stopped.

We do not need more spending or more fear or more hate or more restrictions on immigration. What we need is an efficient, coordinated security apparatus that can act on the often significant warning signs that killers send long before their sprees begin. — The editorial board