How did a disgraced airman, convicted by court-martial of assaulting his wife and child, get access to the weapons he used Nov. 5 to commit the deadliest mass shooting in an American house of worship? The short answer seems to be: not legally. But the case of Devin Patrick Kelley, who murdered 26 parishioners before dying of a gunshot in his flipped car, illuminates a confusing tangle of federal regulations that are supposed to keep guns out of domestic abusers’ hands.

Monday evening, after we originally published this article, the Air Force provided some answers in a statement, saying, “Initial information indicates that Kelley's domestic violence offense was not entered into the National Criminal Information Center database by the Holloman Air Force Base Office of Special Investigation.”

Following revelations from the Air Force, the Department of Defense also released a statement saying it has called for its own inspector general to review the handling of Kelley's record in conjunction wit the Air Force. “The DoD IG will also review relevant policies and procedures to ensure records from other cases across DoD have been reported correctly,” the statement said.

We know that Kelley enlisted in 2010 as an Air Force logistics specialist, and that in 2012, he was court-martialed on two Article 128 counts for assault. He was found guilty, reduced to E-1, sentenced to 12 months’ confinement, and given a bad-conduct discharge. The military denied him a further appeal in 2014; he would be discharged later that year. One of the weapons Kelley used in the murders — a Ruger AR-15 variant dubbed the AR-556 — he purchased at an Academy Sports & Outdoors in San Antonio last April, sources told CNN. (Eyewitness reports suggest Kelley had at least one pistol, too.)

Should Kelley’s UCMJ conviction have prevented him from legally owning guns? It appears so — but the process is tricky and cumbersome. Here is the decision tree:

1. No firearms for dishonorable discharges.

This is an ironclad regulation: Federal law makes it a crime for anyone who has been dishonorably discharged from the military to possess or receive firearms or ammunition — if the gun or ammo “was transported across a state line at any time.” (That last part is necessary for a federal crime to have been committed; many states, though, use the federal standard to bar DDs from gun possession in their jurisdictions.)

In Kelley’s case, neither applies. He got a bad-conduct discharge. Dishonorable discharges, or DDs, are rare even in clear-cut general courts-martial, one former Air Force JAG says:

2. No firearms for felons.

The same federal code bars convicted felons (and those being tried for felonies) from possessing guns. The UCMJ doesn’t classify crimes as “felonies” or “misdemeanors,” but under this law, the civilian federal authorities can consider a crime a felony if it could have been punished by more than a year in jail. “Summary” courts-martial or non-judicial punishments don’t count, but convictions at a special or general court-martial can.

That may very well have applied to Kelley; the nature of his court-martial wasn’t immediately known by press time.

3. No firearms for convicted domestic abusers.

Studies over the years have shown a high correlation between gun violence and domestic abuse, leading critics in the early 1990s to argue that many convicted misdemeanor abusers should have been denied guns but weren’t because their crimes weren’t felonies. The 1996 Lautenberg Act changed this, barring those convicted of misdemeanor domestic violence from owning guns or ammo.

Military policy states — and military law experts agree — that any domestic-assault conviction at a special or general court-martial applies here; NJPs and summary courts-martial don’t. It looks like this provision (and/or the felony provision above) probably applied to Kelley’s conviction, given the length of his confinement and his subsequent denial for a Texas gun license; more on that below.

4. Service members prohibited from possessing guns or ammo for domestic abuse or violent crimes would appear in one or both of two military databases.

Reports of child abuse by a service member, substantiated or otherwise, typically go into a Family Advocacy Plan registry for tracking. Service members can also be asked at any time, particularly when issued weapons, to fill out a DoD Form 2760 certifying that they’re not disqualified from possessing firearms or ammunition. It’s on them to report any disqualifying convictions. 

Criminal convictions in the military system, however, are typically sent by the military authority to the FBI’s National Crime Information Center, where they may be sorted into a couple of federal databases — most notably, the National Instant Criminal Background Check System (NICS), where state authorities and firearms dealers will find them in gun-related background checks. When and how this happens, exactly, varies by military prison facility and law enforcement agency, though. Initial reporting by The Trace suggests the military may never share domestic-abuse information with the FBI, unless the abuser was dishonorably discharged. In Monday night's statement, the Air Force said Secretary Heather Wilson and Chief of Staff. Gen. David Goldfein have called for a “complete review of the Kelley case and relevant policies and procedures.” 

6. State law dictates who gets background checks. Kelley should’ve had two.

On CNN Nov. 6, Texas Gov. Greg Abbott told viewers that “Devin Kelley sought to get a license to carry a gun in the state of Texas, but the state of Texas denied him the ability to get a gun.” He didn’t specify when that happened, but when someone applies for a handgun license in Texas, authorities in Austin perform a background investigation of the applicant that includes local and state records, as well as the FBI’s NICS databases. Looks like Kelley’s didn’t go well.

“So how was it that he was able to get a gun?” Abbott asked. Good question — one worth asking Academy Sports & Outdoor in San Antonio, which reportedly sold Kelley that Ruger AR in April 2016. CNN reported that Kelley had falsified his application for the firearm, stating he didn’t have a disqualifying conviction and he resided in Colorado Springs. Even so, his name would’ve been run against the NICS database by the sporting goods store — and there “was no disqualifying information in the background check conducted as required for the purchase,” CNN reported, citing information from a law enforcement official.

That would suggest that either Academy screwed up the background check somehow — not likely — or the NICS information it got back didn’t include Kelley’s military rap sheet, which now seems more likely given the Air Force's admission that it failed to report Kelley's conviction to the federal authorities. 

We also have eyewitness testimony placing more firearms than just the AR in Kelley’s hands — and we know that, if he bought them privately, person to person, there would likely have been no background checks necessary anyway.

The upshot is that in a nation of roughly 320 million people and 300 million firearms, with a longstanding tradition of individual gun rights and a lot of anger, there are more ways for people with malign intent to get guns than there are to stop them.

UPDATE: This article was updated to include a statement from the U.S. Air Force saying it did not alert authorities of Kelley's domestic violence conviction (Updated 11/6/2016; 7:05 pm EST).