WASHINGTON -- The gunman charged in last month's Charleston, South Carolina, church massacre should not have been allowed to purchase the weapon used in the attack, FBI Director James Comey said Friday.

He outlined a series of missed opportunities and incomplete paperwork that allowed Dylann Roof to obtain the gun that he is accused of using to kill nine people at a historic black church during a Bible study session.

The problem relates to an arrest of Roof weeks before the shooting in which police say he admitted to possessing illegal drugs.

Under federal rules, that admission should have been enough to disqualify him from the April gun purchase. But Comey said the FBI background check examiner who evaluated Roof's request to buy a gun never saw the arrest report because the wrong arresting agency was listed on what she reviewed.

The transaction went through after three days because the examiner didn't have enough information to authorize or deny it.

"If she had seen that police report," Comey said, "that purchase would have been denied."

Comey said he learned about the problem on Thursday night and that FBI officials planned to meet Friday with relatives of the shooting victims. He said he had also directed an internal 30-day review into how the FBI uses criminal background checks in gun transactions.

His announcement came within hours of the Confederate flag's removal from the South Carolina Statehouse. Families of the victims attended the ceremony.