Based on prior reporting from field work and various sources, this reporter can confidently conclude that magic mushrooms are very chill. There’s more than college weekends to back that stance up, though. Past research has suggested they can help with the existential anxiety of cancer, positively change personalities, and even help kick nicotine addictions.

You might wonder, then, why doctors don’t prescribe mushrooms’ active ingredient, psilocybin. Aside from being a schedule 1 drug, scientists haven’t fully understood the chemistry behind how mushrooms produce the chemical—until now. A new study may finally lay the groundwork for a medical-grade psilocybin patients can take.

“Given the renewed pharmaceutical interest in psilocybin, our results may lay the foundation for its biotechnological production,” the researchers write in the study published this month in the journal Angewandte Chemie (it’s German).

Living things make molecules through a series of chemical reactions, similar to how car makers produce cars on assembly lines. Enzymes act as the workers/robots, speeding up the reactions by helping put the pieces together. Actually making psilocybin requires mapping the biological factory.

A 1968 paper (obviously it was in 1968) offered a proposed order of events leading to a finished psilocybin molecule, by adding radioactive elements and watching what happened to them on the assembly line. The researchers thought that maybe tryptophan, the amino acid everyone wrongly says makes you sleepy, was the first piece, which then went through four successive steps to become the finished product.

The new study shows that the 1968 paper got the order wrong, and introduces the responsible genes and enzymes, the workers that do the specific task to get the final product. This time around, mapping the factory required sequencing the genomes of two magic mushroom species, Psilocybe cubensis and Psilocybe cyanescens. Then, the researchers found exactly which genes produce the required enzymes and spliced them into E. coli bacteria. Using those enzymes, they were able to rebuild the factory and create their own psilocybin. Hell yeah.

If you’re interested in the actual steps: It starts with a special kind of tryptophan molecule, with an extra oxygen and hydrogen stuck on, like an anglerfish with a big head and a tail and an extra piece hanging off like the headlight. An enzyme the researchers named PsiD first strips a carbon dioxide molecule off of the tail. Then, an enzyme they called PsiK phosphorylates it, meaning it replaces the headlight’s oxygen with a special setup of phosphorus with some oxygen attached. A final enzyme, called PsiM, works to replace two hydrogen atoms on the tail with methyl groups, or carbon atoms with three hydrogens attached.

There, now you know how to make psilocybin. Go crazy! Re-enact Breaking Bad!

Other scientists thought this was a praiseworthy advance, reports Chemical and Engineering News. “The new work lays the foundation for developing a fermentation process for production of this powerful psychedelic fungal drug, which has a fascinating history and pharmacology,” University of Minnesota, Twin Cities medicinal chemist Courtney Aldrich told them.

There are still regulatory hurdles, and it won’t be tomorrow that your doctor will prescribe lab-made psilocybin. But medical-grade magic mushroom pills could be closer than you think.