Every second, people around the world drink more than 26,000 cups of coffee. And while some of them may care only about the taste, most use it as a way to deliver caffeine into their bloodstream. Caffeine is the most widely consumed psychoactive substance in the world.

Many of us get our caffeine fix in tea, and still others drink mate, brewed from the South American yerba mate plant. Cacao plants produce caffeine, too, meaning that you can get a mild dose from eating chocolate.

Caffeine may be a drug, but it’s not the product of some underworld chemistry lab; rather, it’s the result of millions of years of plant evolution. Despite our huge appetite for caffeine, however, scientists know little about how and why plants make it.

A new study is helping to change that. An international team of scientists has sequenced the genome of Coffea canephora, one of the main sources of coffee beans. By analyzing its genes, the scientists were able to reconstruct how coffee gained the biochemical equipment necessary to make caffeine.