Every year monarch butterflies make a majestic migration from the northerly reaches of Canada all the way to the Gulf Coast. Scientists are fascinated by several facets of this mysterious journey, from how it shapes monarch development to where, exactly, the winged critters end up. New research in the journal Nature helps explain one aspect of the enigmatic trek—how the insects evolved the ability to turn themselves toxic, which keeps them from getting eaten en route.

As caterpillars, monarchs munch on milkweed. That diet would sicken or even kill most animals; the plants produce cardiac glycosides, which disable the sodium pumps that cells use to regulate salt levels. For organisms with hearts, this can result in cardiac arrest. But monarchs never digest the toxins. Instead, in a process called sequestration, they carry the cardiac glycosides inside their bodies as they create cocoons, mature into butterflies, and take flight. Milkweed plants have evolved toxicity precisely so most insects won’t eat them, so being able to absorb their power gives the orange butterflies—along with about 20 other types of insects—access to a food source without much competition. It also renders them toxic to would-be predators.

Carrying poison around has at least some impact on most of these species, and resisting the impact of the toxin takes up energy they could be using for other things, like eating and reproducing. Monarchs handle milkweed better than the rest, and giving fruit flies the same genetic resistance could help reveal why.

Researchers used CRISPR to edit three mutations into a single fruit fly gene known to control the sodium pump. Two of the mutations, which prevent cardiac glycosides from binding to the pump, had already been studied in monarch butterflies. But those two mutations made the fruit flies far more prone to seizures, and they quickly died. Adding a third, previously-unidentified mutation to the mix helped to compensate for the bad impacts of the other two.

By testing the mutations one by one, “they’re able to really replay the tape of evolution,” says Marcus Kronforst, a University of Chicago ecologist. That’s because the mutations had to occur in a specific sequence to avoid killing the flies before imbuing them with toxin-sequestering superpowers.

The thrice-mutated “monarch flies” are as resistant to milkweed toxins as monarch butterflies themselves, and 1000-times less sensitive to it than their wild counterparts. They also carry the toxin with them from their larval stage (baby fruit flies have the misfortune of being maggots rather than caterpillars) to adulthood. It’s the first time anyone has used CRISPR to study evolution by actually recreating the development of a specific trait—in this case, toxin resistance—in a living, multicellular organism step by step. But studying the monarch flies may not lead to generalizable knowledge about how this process evolved in all 20 types of insects who have this trait, says Peter Andolfatto, the author of a paper published in August that used different gene-editing techniques to recreate the same mutation in fruit flies.

“These three sites have evolved in a very similar way across multiple insect orders,” he says, but his team’s work found that the order of the mutations isn’t always the same. “The way that monarchs have done this might not be representative of the way other groups have done this.”

The research doesn’t just figure out the way the three mutations work together to allow the monarch flies to eat otherwise-poisonous milkweed. “It also demonstrates the necessary first step to the ‘monarch flies’ becoming toxic themselves,” writes Naomi Pierce, a biologist who studies butterflies at Harvard University, in an email to Popular Science. “It’s a truly beautiful paper.”

But for all that, this is also a cautionary tale about CRISPRing animals, says University of California biologist and study author Noah Whiteman. The fruit flies, even with three mutations, are very sensitive to external motion: If you bang the test tube they’re flying in, they fall down and take almost two minutes to get airborne again. Whiteman and his team are working on figuring out why that’s not true for monarch butterflies. It’s possible the flies have off-target mutations, he says, meaning that CRISPR edited some as-yet-unidentified random genes along with the ones his team sought to tweak. It’s a stark reminder that we’re a long way off from solving all our own species’ problems with genetic engineering. Even though they have the incredible ability to live off milkweed, Whiteman says, “these are very sick flies.”

This article has been updated to include comment from the author of a similar study.