Updated at 3:30 p.m. ET

FBI Director James Comey said the man accused of killing nine people in a Charleston, S.C., church should never have been allowed to purchase a weapon.

Comey said flaws in paperwork and communication between a federal background check worker and state law enforcement allowed Dylann Roof to buy a handgun in South Carolina on April 16 — weeks before he allegedly attacked black churchgoers in a failed attempt to fuel a race war.

"We are all sick that this has happened," Comey told reporters Friday. "We wish we could turn back the clock. ... What we can do is make sure we learn from it, get better."

Comey said he had ordered an internal review of FBI policies and procedures surrounding background checks for weapons purchases. The bureau's examiners conduct criminal checks before guns are bought in about 30 states; the remainder of states generally perform their own checks.

Here's what the FBI director says happened.

On April 11, Roof tried to buy a handgun at a store in West Columbia, S.C. And under normal procedure, that paperwork was assigned to an examiner at the FBI's unit in West Virginia. The unnamed FBI examiner turned up Roof's arrest on March 1 on a felony drug charge — but the system did not show a conviction, and it wasn't enough to deny the purchase.

So she kept checking. And, Comey said, the first mistake comes in here. Roof's rap sheet mistakenly listed the Lexington County, S.C., sheriff's office as the arresting authority. The examiner then reached out to the sheriff's office and prosecutors in Lexington for more information.

The sheriff's office told her the Roof case was not theirs and advised her to check with police in Columbia, S.C.

And now, Comey said, the second mistake was made. The examiner consulted a contact sheet for local contacts in Lexington County, and didn't see anything for Columbia. So she called West Columbia, where Roof allegedly tried to buy the gun, instead. Local authorities in West Columbia said they had no record of the case, and the examiner turned to other matters while she waited to hear from prosecutors.

Under the normal process, if gun dealers do not hear back from the FBI with a flat denial in three business days, they are free to sell the weapon to the person who filled out the biographical paperwork. And that's what the gun store did with Roof on April 16.

Weeks later, on the evening of June 17, Roof allegedly sat through an hourlong Bible study session in the historic Emanuel African Methodist Episcopal Church in Charleston before opening fire, killing pastor Clementa Pinckney and eight other parishioners. Roof now faces state charges, including murder and a weapons offense. Federal authorities are investigating whether Roof, who posted a hate-fueled manifesto online and posed with photos of the Confederate battle flag, committed a hate crime, as well.

The FBI background check worker, described by Comey as an experienced examiner who has been "struggling" over the church shooting, never heard back from prosecutors in Lexington. But if she had called police in Columbia and seen their arrest record on Roof, she would have known he had admitted to possessing a controlled substance. And that, Comey said, would have triggered an FBI denial of his weapons purchase on the grounds that he was "an unlawful drug user or addict."

Comey said FBI officials in South Carolina, who have developed a relationship with family members of the church shooting victims, would brief them on the situation and his call for an internal review.

"All of us grieve for their unspeakable loss," Comey said. "I want to know if there are ways to improve our process, our procedures and our training."

Comey said he gathered and assessed the facts Thursday night, notifying the deputy attorney general and the attorney general, Loretta Lynch.

Senate Judiciary Committee Chairman Chuck Grassley, R-Iowa, said in a statement: "It's disastrous that this bureaucratic mistake prevented existing laws from working and blocking an illegal gun sale. The facts undercut attempts to use the tragedy to enact unnecessary gun laws. The American people, and especially the victims' families, deserve better."

Copyright 2016 NPR. To see more, visit http://www.npr.org/.