(Reuters) - A federal judge has dismissed 16 lawsuits filed by survivors of a 2015 mass shooting at a South Carolina church who sued the government over the failure of an FBI-run background check system to prevent the purchase of the murder weapon.

FILE PHOTO: Dylann Roof sits in the court room at the Charleston County Judicial Center to enter his guilty plea on murder charges in state court for the 2015 shooting massacre at a historic black church, in Charleston, South Carolina, U.S., April 10, 2017. REUTERS/Grace Beahm/Pool

U.S. District Judge Richard Gergel also criticized what he called “abysmally poor” Federal Bureau of Investigation policies for the system that allowed Dylann Roof buy the gun he used to kill nine people, all African-Americans, at a historic black church in Charleston.

In his ruling released late Monday, Gergel said that the government had immunity from being sued for its policies, “even really bad policy choices.”

Wrongful death lawsuits filed by survivors and family members of victims of the shooting alleged that at least one of the background check databases maintained by the federal government had information that should have prevented the firearm sale.

Gergel criticized the FBI’s policy to deny background check examiners access to the database, known as N-DEx.

If the examiner assigned to Roof’s purchase request had been able to access N-DEx, he would have seen Roof’s 2015 drug arrest and would have barred him from buying the gun, Gergel wrote in his decision.

The government’s argument in the case that it had to deny background check employees access to N-DEx, as it was restricted to law enforcement agencies, was “simple nonsense,” Gergel wrote.

The judge suggested the FBI take corrective steps to prevent a similar failure in the future.

An FBI spokeswoman said the agency does not comment on litigation cases.

Mullins Mcleod, a lawyer representing several of the plaintiffs in the case, was not immediately for comment.

The FBI runs federal background checks for gun dealers in more than 30 states, including South Carolina.

The examiner who conducted Roof’s check did not see a police report in which Roof admitted to unlawful drug possession, which would have barred him from buying the weapon, former FBI director James Comey said following the shooting.