People have brewed beer for thousands of years, but there are some things that brewers still don’t have down to a science. Despite the best efforts of brewers everywhere, sometimes a tiny, nefarious bacterium will manage to squirm its way into a batch of beer, ruining it for everyone.

Usually, brewers don’t find out about the presence of bacteria until too late. They rely on cultures, taking small samples of beer and incubating them in petri dishes to see if harmful bacteria grows. But some breweries are taking a more proactive approach.

As the Verge reports, breweries like Russian River are turning to a quick, easy DNA testing method that takes just a few hours, and can identify beer-contaminating culprits such as bacteria from the Pediococcus and Lactobacillus genuses, which can ruin a beer’s flavor.

There are a few different brands of the test, but they all use the same basic technique: PCR, or polymerase chain reaction.

In order to quickly identify a tiny amount of bacteria in a beer sample, PCR searches for a small snippet of the offending DNA. If the DNA is found, PCR makes billions of copies of it so that it’s more easily detected by a reader (which the Verge likens to a pregnancy test). The test alerts brewers to a potential problem before it gets too out of control, resulting in less wasted beer and money.

PCR is also used in numerous other quality-control applications, identifying everything from counterfeit olive oil to malaria.