South Carolina shooting suspect Dylann Roof should not have been able to purchase the gun used in the massacre at Charleston’s Emanuel African Methodist Episcopal Church, the FBI said Friday.

FBI Director James B. Comey said that Roof was able to obtain the weapon, which was used to kill nine African-Americans in a racially motivated attack on the historically black church on June 17, because of shortcomings in the screening system for gun purchases, the Washington Post reported.

“This case rips all of our hearts out, but the thought that an error on our part is connected to a gun this person used to slaughter these people is very painful to us,” he said, according to the D.C. paper.

Three days after the shooting, online activists found what is believed to be Roof's website. It includes a racist manifesto and many troubling pictures of Roof, which depict him waving the Confederate battle flag, burning the American flag and posing beside neo-Nazi symbols.

The bureau runs a system called the National Instant Criminal Background Check System to prevent people like Roof from purchasing firearms.

Comey said the error in the national background check system allowed Roof to get his hands on the .45-caliber handgun, which was also featured prominently in his pictures, despite having been busted for drugs.

Roof had been arrested for possessing narcotics in February, but he was not listed in the criminal databases that should have prevented him from purchasing the weapon.

The background check examiner who evaluated the alleged gunman’s request to purchase a gun never saw his arrest report because the wrong arresting agency had been listed in his file, Comey said.

“We are all sick this happened,” he said, according to the New York Times. “We wish we could turn back time.”

Citing court records and government documents, the New York broadsheet said that flaws in the system have been exploited in the past; one such loophole reportedly allowed thousands of barred individuals to purchase guns over the past 10 years.