A few weeks after a a gunman murdered nine members of a prayer group at a historically black church in Charleston, South Carolina, the then-director of the FBI acknowledged that a cascade of errors within the federal gun background-check system had allowed the shooter to erroneously purchase the weapon he used in the act.

Dylann Roof, a white supremacist with a criminal record, had been allowed to walk out of a gun store with a .45-caliber Glock pistol because his background check had taken longer than three business days to process. This is known as a default proceed sale. Because of poor record-keeping practices by a local police department, the FBI examiners missed that Roof had confessed to using drugs during an arrest, a disqualification from gun ownership, according to James Comey, the bureau’s director.

“What we can do is make sure that we learn from it, get better, and work to ensure that we catch everything,” Comey said in a statement on July 10, 2015.

Comey is gone, ousted by President Trump in an act of high political trauma, but the failures exposed by the horrific event persist. Since it launched in 1998, the National Instant Criminal Background Check System, or NICS, has completed almost 262 million checks. The system screens buyers in all gun purchases and transfers at federally licensed stores across the country, as well as applicants for concealed-carry permits. It’s an unsexy but essential part of the FBI’s job, a first line of defense against criminals getting hold of deadly weapons.

In several key ways, though, it is not doing the job its creators intended. The system still uses incomplete databases of criminal and mental health records. It is understaffed and works much slower than it once did. And people who are wrongly denied a sale are out of luck: the appeals system has been put on ice.

Here are three top challenges facing the system that await Comey’s successor.

Troves of missing records

FBI examiners can’t do their jobs without relying on cities, states, and other federal agencies to submit records that disqualify people from gun ownership. But many agencies do not report records to NICS — sometimes with deadly consequences.

In 2007, Seung-Hui Cho purchased the gun he used to kill 32 people at Virginia Tech despite a disqualifying mental health record. He was able to pass a background check because Virginia did not require courts to report all mental health records to the FBI.

In the time since the shooting, about half of the states passed laws requiring comprehensive submission of disqualifying mental health records. NICS’ total number of psychiatric records on file increased by 700 percent from 2007 to January 2014, suggesting that many such records were missing before states compelled their courts to submit them.

Congress also authorized billions in assistance in 2008 to states to improve record keeping. But participation was anemic. Almost 90 percent of that money was never dispensed. And it’s believed that many relevant records are missing from the FBI’s files. South Carolina, a state with a population of 4.9 million people, has only submitted five records of people who are unlawful users of controlled substances.

Sometimes records have been removed as a result of interagency disputes. After a disagreement between the ATF and FBI earlier this year over who qualifies as a “fugitive from justice,” half a million records were removed from NICS.

The same goes for open warrants. As The Trace reported in March:

According to a Bureau of Justice Statistics report published in February, at the end of 2014 there were 7.8 million active-warrant records in state warrant databases, but only about 2.1 million warrant records in the federal NCIC database. More than 70 percent of the records in the state databases are not available to gun background-check screeners or other federal law enforcement officers who rely on NCIC.

An overworked staff

While the volume of gun sales — and background checks — surged to unprecedented heights during President Obama’s administration, the number of people tasked with completing checks held level.

NICS has employed 230 examiners since at least 2012. That year, examiners processed 16.5 million background checks. The same number of employees completed 27.5 million checks in 2016.

In January 2016, Stephen Morris, the FBI’s assistant director, described the situation as “a perfect storm.” The demand for checks was so high, and the level of staffing so low, that the FBI was cancelling NICS employees’ leave, he said. That same month, President Obama requested that Congress authorize funds for 230 more NICS examiners to ease the burden. But the Republican-controlled Congress did not grant the request when it funded the FBI for fiscal year 2017.

As examiners’ workloads increased without relief, the conditions became ripe for more errors or incomplete checks, which resulted in more default proceeds.

The added workload also meant that checks took much longer to process. In 2015, it took NICS an average 281 seconds to complete a check, up from 32 seconds in 2012.

Dealing with a backlog in appeals

The Obama-era surge in background checks caused NICS to neglect one of its important functions: appeals. In some cases, individuals are denied a gun purchase when they shouldn’t be. In 2015, the last year for which data is available, NICS denied 106,556 background checks. In 3,625 cases — or 3.4 percent — a denial was overturned on appeal.

In October 2015, citing manpower shortages, NICS stopped accepting appeals altogether. The FBI didn’t restore the function until February of this year, but examiners are still working on appeals submitted almost two years ago.

A broken appeals process upsets gun-rights advocates, who say it undermines faith in the fairness of the background-check system. The National Rifle Association has called delayed appeals “sinister,” insinuating that they are deliberate attempts to dissuade people from exercising their Second Amendment rights.