Devin Kelley, the former airman who shot and killed 26 people in a Texas church Sunday, previously escaped from a behavioral health hospital after being caught sneaking firearms on base and threatening to kill his superiors.

According to an El Paso, Texas, Police Department incident report posted online by Houston TV station KPRC, Kelley escaped from the Peak Behavioral Health Services facility in Santa Teresa, New Mexico, and fled to Texas. He was reported missing June 7, 2012.

Kelley “suffered from mental disorders” and “was a danger to himself and others,” the report said. Kelley snuck guns onto Holloman Air Force Base in New Mexico in an attempt to “carry out death threats that [he] had made on his military chain of command,” the report said.

Kelley was last seen at the behavioral health facility in New Mexico June 7, 2012, and was detained by El Paso officers six days later.

At the time, Kelley was facing domestic assault charges, two of which he would plead guilty to later that year. Kelley was sentenced to 12 months confinement and a bad conduct discharge.

His conviction should have left him unable to legally buy firearms. However, the Air Force said Monday that Holloman’s Office of Special Investigations failed to enter his domestic violence record into an FBI database checked by gun sellers as part of a background check.

The Air Force and the Defense Department have now launched investigations to find out what went wrong in Kelley’s case, and to make sure records in other cases have been properly reported.

The incident involving the behavioral health hospital and his court-martial were just two of many run-ins Kelley had with the law.

In February 2014, sheriff’s deputies arrived at his family’s home in New Braunfels, Texas, just after 10 p.m. one night to investigate a potential domestic violence case.

Citing a sheriff’s office report, Comal County spokesman Paul Anthony said a friend of Kelley’s girlfriend told authorities she received a text message from the girlfriend that indicated “her boyfriend was abusing her.” The report identifies the girlfriend as Danielle Shields and says Shields reported that “her arms were red.” It includes no additional details about what caused them to be red.

Shields said Kelley had “told her to pack a bag,” according to the report.

When sheriff’s deputies arrived, people at the home said there was a “misunderstanding,” according to the report. It doesn’t make clear who spoke to deputies. No arrests were made.

Kelley married Shields two months later.

Several months later, in August 2014, Kelley was charged with misdemeanor animal cruelty. the Associated Press reported. One neighbor told a deputy that Kelley chased a dog, jumped on top of it and struck the dog with a closed fist several times, according to an incident report released Monday. Another neighbor says Kelley grabbed the young husky, threw it into the air, then onto the ground and dragged it to his camper.

According to local court records, he was given a deferred probationary sentence and ordered to pay $368 in restitution. A protection order was also issued against him in 2015 on behalf of the local Humane Society, according to court records.

The Associated Press contributed to this report.