Researchers don’t know exactly how psilocybin, a psychoactive compound found in psychedelic mushrooms, evolved. Now, a new study adds to the mystery: Its findings reveal that two different groups of fungi came up with independent ways to produce the seemingly magical molecule.

In a paper published September 21 in the journal Angewandte Chemie International Edition, scientists analyzed the genes and proteins used by Psilocybe and Inocybe mushrooms to make psilocybin. To their surprise, they found that the two genera of mushrooms produce the compound using completely different pathways.