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.

“Can you keep making it highly concentrated, or does it become toxic to the organisms that you're actually using to produce it, and therefore you have a limit?” asks Jeff Raber, CEO of the Werc Shop, a lab that’s picking apart the components of cannabis.

Regardless of production hurdles, the beauty of this kind of bioengineering is that it gives researchers a powerful platform to dig into not just what each cannabinoid might be useful for—whether treating anxiety or inflammation or epilepsy—but how the many cannabinoids in the plant might interact with one another. This is known as the entourage effect: CBD, for instance, seems to attenuate the psychoactive effects of THC.

By selectively churning out these cannabinoids in the lab, it’ll be easier for researchers to play with them in isolation and with each other, without having to wade through hundreds of other compounds you’d find in pure flower. “Ultimately, a molecule is a molecule,” says Raber. Indeed, cannabinoids made from yeast are the same cannabinoids the plant makes. “It gives flexibility in formulation, it gives broader utility perhaps, and it may eventually scale faster than plants. Regulators might feel a lot better about these types of approaches than those that are fields and fields and fields of plant material.”

And this doesn’t stop at cannabinoids. What Raber and other researchers are pursuing is essentially a reconstruction of cannabis’ chemical profile. Terpenes, for example, are what give weed its characteristic smell, yet you’ll find these across the plant kingdom: Limonene isn’t super abundant in cannabis, but it is an abundant product of the citrus industry. The idea is that instead of going through the grief of extracting small amounts of limonene from a cannabis plant, you can get it from lemons instead.

The eventual goal is to be able to tailor cannabis products, such as tinctures, to a consumer’s preferences. This would allow for a customized ratio of CBD to THC, and eventually other cannabinoids and terpenes, which themselves may play a role in the entourage effect. The terpene linalool, for example, may have anti-anxiety effects.

In the nearer term, let us celebrate yeast, that miracle microbe and creator of all things good: bread, booze, and bioengineered cannabinoids.

This story originally appeared on wired.com.