Researchers suspect that psilocybin — the psychedelic compound that puts the “magic” in magic mushrooms — could prove useful for treating a host of mental health problems, from depression to anorexia.

If that proves to be the case, though, there’s no easy way to mass produce the compound. Growing enough of the mushrooms that make it naturally would require significant space and time, while the synthetic version of psilocybin is still incredibly expensive.

But now, a team of researchers from Miami University in Ohio has found a way to coax the bacteria E. coli to produce psilocybin as a byproduct — potentially opening the door to a cost-effective means of mass-producing the promising compound.

To create this psilocybin-producing E. coli, the team started by implanting psilocybin-producing genes from magic mushrooms into the bacteria, a process detailed in a study published in the journal Metabolic Engineering.

Once they saw that the bacteria could produce psilocybin, they took their most promising strain, dubbed pPsilo16, and set about tweaking the growth conditions to optimize production.

“What’s exciting is the speed at which we were able to achieve our high production,” researcher Andrew Jones said in a press release. “Over the course of this [18-month] study, we improved production from only a few milligrams per liter to over a gram per liter, a near 500-fold increase.”

Not only is this the first time anyone has managed to coax a bacteria into producing psilocybin, but it also marks the highest concentrations of production for any bioengineered organism.

Still, the team thinks it can do better. It’s now tinkering with its engineered E. coli in the hopes of making it an even more efficient producer of psilocybin — and that could prove invaluable if the compound turns out to be as useful a medical treatment as many researchers suspect.