The gunman in Sunday’s mass shooting in Sutherland Springs, Texas, should not have legally been able to buy or own a firearm, officials confirmed to reporters on Monday.

The 26-year-old shooter, Devin Kelley, had previous violent criminal convictions that should have barred him from purchasing a gun under federal law, reports the New York Times. Still, in April 2016, he legally bought an AR-556 assault rifle at a licensed store in San Antonio, which he would later use to fatally shoot 26 people at First Baptist Church in Sutherland Springs before eventually turning the gun on himself.

Some gun control advocates and domestic violence experts contend that this kind of oversight (or lack thereof) is not uncommon. Loopholes and weaknesses in the application of federal law, they say, allow violent criminals access to guns and create a need for states and localities to step in and plug the holes.

In 2012, while he was still serving in the U.S. Air Force, Kelley was convicted of “assault on his spouse and assault on their child” after breaking his infant stepson’s skull. He was sentenced to 12 months’ confinement, and in 2014, he was released from the military with a bad conduct discharge.

Federal gun laws specifically ban convicted domestic abusers and violent felons from possessing firearms. But the Air Force failed to enter Kelley’s convictions into a federal database for background checks. As a result, Kelley passed a background check when he purchased the assault rifle in April 2016, as well as three other rifles in the previous four years.

The Air Force is reportedly conducting an internal review of Kelley’s case and its policies and protocols for reporting crimes to the federal government.

“We know that we can do a better job in making sure that people who aren’t legally able to possess guns actually do not own them,” says Shannon Frattaroli, an associate professor at Johns Hopkins Bloomberg School of Public Health. “But the positive news is that there are some efforts underway to see how states and localities can work together to make sure that people who are legally barred from owning firearms are actually dispossessed of those firearms.”

That's the hard part. Federal law lacks an enforcement mechanism for taking guns that were legally bought out of the hands of people once they're convicted of violent felonies or domestic abuse. But, says Frattaroli, “replication [of federal laws] at the state level allows states and localities to implement and enforce these laws.”

Across the country, 27 states have laws barring convicted domestic abusers, as well as those subject to restraining orders, from owning a gun, The Washington Post reports. Seventeen of those also require domestic abusers to relinquish their guns. The rest function on a sort of honor system.

study by the Boston School of Public Health found that states requiring people under restraining orders to relinquish their guns have a 14 percent lower rate of intimate-partner homicides than those that don't.

At Johns Hopkins, Frattaroli and her partners have been involved in research working with local law enforcement agencies to help them build infrastructure for dispossessing domestic abusers of their firearms.

“If we can take the steps to implement these laws, then we have good reason to expect reductions in some of the most severe outcomes for armed batterers,” she adds.

Another problem with federal law is the so-called “boyfriend loophole,” which refers to the law’s exclusive application to spouses, ex-spouses and partners with children together. In other words: boyfriends and girlfriends don’t count as domestic abusers for the purposes of gun ownership. Several states have also stepped up to cover this loophole, Frattaroli says.

The Sutherland Springs shooting was likely connected to a domestic dispute involving Kelley’s mother-in-law, who regularly attends First Baptist Church. The mother-in-law was not present at the time of the shooting.

Texas, for its part, has laws prohibiting domestic abusers and people under restraining orders from owning guns, and it extends the definition of domestic violence outside marriage or partners with children. It does not, however, have a law requiring relinquishment of guns by these individuals. Even if it did, that likely wouldn't have impacted Kelley's access to guns since the military failed to report his crimes. But states themselves are on the hook for their own reporting failures. 

A report by the liberal Center for American Progress suggests states might be under-reporting domestic violence crimes to the FBI, allowing people to pass gun background checks when they shouldn’t.

Kelley is the latest in a string of men with a history of domestic violence to carry out a terrorist attack or mass killing. James Alex Fields, the man who plowed his car into counter-protesters in Charlottesville, Va., earlier this year, was also among these men. Omar Mateen, the Pulse nightclub shooter, and one of the Boston Marathon bombers, Tamerlan Tsarnaev, were two others.

“As a country, we have to realize the importance of taking domestic violence seriously and recognizing it for the crime it is,” Frattaroli says. “There’s a reason the federal government and many state governments have decided to step in and make this a prohibiting factor for the purchase and possession of guns.”

*This story has been updated.