We as a species would be miserable without yeast. Baker's yeast has given us leavened bread for thousands of years. And I don’t even want to begin to imagine a world without beer and wine, which rely on yeast to convert sugar into alcohol.

Now researchers have turned to yeast to do something more improbable: manufacturing the cannabis compounds CBD and THC. By loading brewer’s yeast with genes from the cannabis plant, they’ve turned the miracle microbes into cannabinoid factories. It’s a clever scheme in a larger movement to methodically pick apart and recreate marijuana’s many compounds, to better understand the plant’s true potential.

The process goes like this. Two different yeasts produce either THC or CBD, depending on what kind of enzyme they carry. Importantly, both carry the cannabis genes that produce CBGA. “CBGA is this kind of central cannabinoid that's the mother of all the other cannabinoids,” says UC Berkeley chemical engineer Jay Keasling, coauthor on a new paper in Nature detailing the technique.

To make THC, that yeast produces CBGA, which then turns into THCA thanks to the yeast's particular enzyme. For the CBD yeast, its own particular enzyme turns the CBGA mother cannabinoid into CBDA. (Alphabet soup, I know, but stick with me.) Now you've got THCA and CBDA, which turn into THC and CBD with the application of heat.

The end bit is not dissimilar from what's going on with the cannabis plant itself. If you were to eat raw cannabis, it’s unlikely you’d get high, because it's mostly THCA. It's only after you apply heat that THCA transforms into THC. (Though small amounts of THCA convert to THC over time as cannabis flower cures.) Edibles work because manufacturers first transform THCA into THC with a process called decarboxylation.

The reason researchers and cannabis companies are interested in alternative ways of producing cannabinoids is that working with the original plant is messy and complicated. First of all, growing the stuff takes a lot of time, water, and energy (if you’re cultivating indoors). Extracting certain cannabinoids from flower is also a hassle. If you’re only after CBD, for example, there’s a chance your extract could be contaminated with THC. This is of particular concern if you want to isolate CBD for use as a medicine—it’s been shown, for instance, to be remarkably effective in treating epilepsy.

Having a vat of yeast churning out pure, non-psychoactive CBD promises to massively simplify production. “Being able to produce that in a way that's uncontaminated with THC is a pretty valuable thing,” says Keasling. Especially since the FDA might want to have a word with you if you accidentally dose patients with a psychoactive substance.

Cannabinoid-producing yeast may also make it easier to study cannabis in the first place. We’re talking about a wildly complicated plant here, with more than 100 different known cannabinoids so far. Some of these compounds are more prevalent than others—modern cannabis strains are packed with THC, because cultivators have bred strains to be ever more intoxicating over the years. But a cannabinoid like tetrahydrocannabivarin, or THCV, shows up in much lower amounts. “Now we're going to have a handle on being able to produce these things in a pure way, and in a relatively simple way, that maybe we can start to test what their functions are,” says Keasling.

Engineered yeast have been used to tackle the scarcity problem in other ways before. In the 1960s, researchers discovered that the taxanes from Pacific yew tree bark can fight cancer. All well and good, except for the Pacific yew, which conservationists feared would go extinct in the hands of an eager medical establishment. But as with this cannabinoid-producing yeast, researchers engineered microbes to help make the drug—deforestation-free.

For cannabinoids, the key benefit is scale. The idea is that you could crank out vast amounts of CBD in vats far more easily than by planting greenhouse after greenhouse of cannabis plants. (Which is not to say some folks won't still appreciate their cannabis grown the old fashioned way.) But to make it as efficient as possible, you’d need to work with the highest possible concentrations of cannabinoids. That is, you’d want optimize your yeast to churn out a whole lot of product.