Humans have been consuming cannabis for millennia, but scientists are still largely in the dark about the devil’s lettuce. Thanks to new research, we now have a potential answer to one enduring pot science mystery: Why does weed have the special chemical compounds that affect humans, and other plants don’t?

I speak, of course, of THC and CBD, compounds known as cannabinoids that are found in cannabis and have various effects on humans. THC is well-known as the main psychoactive component in cannabis (i.e. it gets you high), and CBD has recently become fashionable as an ingredient in everything from drinks to cosmetics.

According to a study published in the November issue of Genome Research, these two distinct compounds didn’t always exist in the plant we now call cannabis. According to the study, millions of years ago ancient viruses may have colonized the plant's genome and accelerated an evolutionary process that changed its DNA and gave us THC and CBD.

“The proteins [for THC and CBD] are embedded in this huge mess of virus-like sequences,” said Tim Hughes, a professor of molecular genetics at the University of Toronto and co-author of the study, over the phone. “One thing that these sequences are known for is facilitating the rearrangement of the chromosome, and they’re actually a bit dangerous in that way.”

According to Hughes, these viruses could have accelerated an evolutionary process that resulted in a single enzyme gene in cannabis mutating into two, eventually giving us THC and CBD. “It’s easy to imagine that, over a long time scale, this process happened over and over again in this part of the chromosome where these two enzymes are,” he said.

This change led to ancient cannabis splitting into chemically distinct types, and humans then selected for plants with desired characteristics such as high THC, according to a press release for the study.

It’s hard to say what cannabis was like before ancient viruses helped it develop the properties we’re familiar with today, but according to Hughes some of its closest relatives are innocuous plants like mulberry and hops.

Read More: Canadian Researchers Are Stoked About Access to Legal Weed

The discovery that ancient viruses are probably why people light up some cannabis to unwind is a byproduct of Hughes and his colleagues’ research, which constitutes the first full map of the cannabis genome to be published academically. In February, Colorado-based startup Sunrise Genetics unveiled a map of the cannabis genome at a conference but didn’t publish a paper, saying it would share the work publicly “in less than a year.” Hughes and his colleagues published a draft cannabis genome in 2011, but it wasn’t detailed enough to reveal the position of genes on the chromosome.

Such maps are essential to improving our impoverished understanding of the cannabis plant. Hughes and his colleagues’ map is already paying dividends beyond discovering the possible role of viruses in producing THC and CBD. According to the researchers, they’ve also identified a gene responsible for producing a third cannabinoid called CBC.

And there’s a lot left to learn about a plant that many people regularly consume, but science has yet to fully understand. A big one, according to Hughes, is what use THC and CBD have for the cannabis plant itself, assuming that these compounds developed long before humans walked the Earth. “It’s just fortuitous that they have these effects on people,” Hughes said.

We could soon see more studies that probe the fundamental unknowns of cannabis science thanks to an emerging new wave of research in the wake of the plant’s legalization in Canada. Previously, it was difficult for researchers to get their hands on the plant to study, and the money needed to undertake their research. Now, that’s changing, and in turn so is our understanding of cannabis.

“It’s a plant, and it does these biochemical things, and it’s not like we don’t have the ability to do all the same things that we can in other plants, and animals, and microbes,” Hughes said. “It’s just that nobody’s been doing it because we couldn’t.”