We’re in the middle of an antibiotic crisis that public health experts have been warning about for years. While antibiotics are a miracle of modern medicine, they’re being over used and abused—30% of prescriptions are unnecessary, a new study found and yet doctors continue to prescribe them inappropriately and the agricultural industry relies on them to keep animals plump. Such overuse is leading to smarter bacteria that are evolving into super bugs that can resist nearly every antibiotic drug available today.

To avoid a world of rampant, untreatable bacterial infections, experts say cutting back on unnecessary use of antibiotics is critical. That includes prescribing the drugs only for bacterial infections, against which they work, and not for viral infections. But because people with bacterial infections—people with cold symptoms, say—tend to feel similarly to those with viral infections—with flu symptoms—many doctors still prescribe the drugs for both.

Now, scientists at Stanford University and Cincinnati Children’s Hospital Medical Center report on a blood test that can distinguish between bacterial and viral infections. The test looks at the proteins made by seven genes; in the presence of bacteria, four of the genes become more active, while in the presence of viruses, three of them churn out more proteins. By measuring this, the test can tell with reliable certainty whether an infection is caused by a bacteria or virus.

This was a viruses was a surprise to the researchers. “The notion that there are just seven targets with really excellent accuracy was pretty shocking,” says Dr. Timothy Sweeney, a researcher at Stanford University and lead author of the paper, which was published in Science Translational Medicine.

Previous studies identified dozens or hundreds of genes that were associated with either bacterial or viral infections, but those analyzed a single set of data from a group of patients. Sweeney and his team combined publicly available data from nearly two dozen groups of people with documented infections. These ranged from cases of the common cold to hemorrhagic viral fevers, to ear infections and septic shock. Teasing apart the genetic signatures of these people led to the narrowed set of seven genes that showed consistently different activity in the presence of bacteria and viruses.

According to the Centers for Disease Control, about a third of the 154 million prescriptions that doctors write for antibiotics are unnecessary, and likely do more harm in terms of promoting bacterial resistance, than good in treating infections. The reasons for that include patients who demand drugs to treat their symptoms, even if they aren’t caused by bacteria, doctors who are too pressed for time to educate their patients about the difference between bacterial and viral infections, and a better-safe-than-sorry mentality to protect hospitalized patients, from dangerous, potentially fatal infections like sepsis.

“We don’t really have a good test where we can say you don’t have an infection so we can safely withhold antibiotics,” says Sweeney.

This panel of seven genes may change that, but it will take a few years before it becomes reliable enough to use in the clinic. While Sweeney and his colleagues tested the panel in a group of nearly 100 children with infections, more testing in more patients is needed to verify the panel’s accuracy. For now, the test also takes four to six hours—too long when the patient might be suffering from sepsis, which can progress quickly within hours.

The goal is to perfect the technology to scan the blood for the seven genes’ profile in about an hour. “A lot of people said we need a test like this, and we hope our test, or one like it, will help to reduce the crazy over use of antibiotics that is threatening not just medicine but whole parts of our society based on our inability to treat certain infections,” says Sweeney.

This article originally appeared on Time.com.