The gunman accused of committing the deadliest mass shooting in modern Texas history sent threatening texts to his mother-in-law before targeting the church where she sometimes worshiped, authorities said on Monday.

Devin Kelley, 26, opened fire on the First Baptist Church in Sutherland Springs on Sunday, killing 26 people and wounded 20 others. His wife’s grandmother was among the victims. He was later found dead of a self-inflicted gunshot wound.

“It’s a senseless crime, but we can tell you that there was a domestic situation going on within this family,” said Freeman Martin, the regional director of the Texas Department of Public Safety. “He had expressed anger toward his mother-in-law.”

As information has emerged about Kelley’s background, he appears to share a common trait with many American mass shooters: a history of domestic violence.

In 2012, Kelley, who served at Holloman Air Force Base in New Mexico, was court-martialed for assault on his spouse and assault on a child. “He assaulted his stepson severely enough that he fractured his skull, and he also assaulted his wife,” Don Christensen, a former chief prosecutor for the Air Force, told the New York Times. “He pled to intentionally doing it.”

That year, his then-wife filed for divorce, according to court records. He was sentenced to 12 months behind bars, and received a bad conduct discharge. In 2014 he was remarried, according to the Times.

His conviction should have barred him from legally purchasing firearms, according to military law experts who spoke with HuffPost. Under the Lautenberg amendment, individuals who are convicted of a domestic violence misdemeanor are prohibited from owning or buying guns.

It is unclear how Kelley was able to legally buy a firearm given his domestic violence record.

While the military’s penal system doesn’t use the term “misdemeanor” or “felony,” convictions involving domestic violence typically trigger the gun ban, explained Rachel VanLandingham, a professor at Southwestern Law School in Los Angeles.

“This case is tragic because it sure seems like this is the poster child for whom the Lautenberg amendment was supposed to be written,” she said.

Academy Sports + Outdoors, a sporting and hunting goods store in Texas, confirmed to HuffPost that Kelley purchased two firearms from them ― one in 2016 and one in 2017.

Both sales were approved by the National Instant Criminal Background Check System, which raises questions about why his domestic violence conviction did not trigger a gun prohibition. The FBI did not immediately respond to a request for comment.

In the U.S., most mass shootings involve domestic violence, according to research from Everytown for Gun Safety, which defines a mass shooting as a single incident in which four or more people are fatally shot, not including the perpetrator.

Between 2009 and 2016, in 54 percent of mass shootings the perpetrator shot a current or former intimate partner or family member. Everytown also found that in nearly half of these cases, the perpetrator exhibited warning signs before the killing, such as recent acts of violence, threats or violation of a protective order.

This story has been updated to include information about Kelly’s gun purchase and comments from a former Air Force prosecutor.