Kellyanne Conway is best known as a spin artist, a mascot, and a folk hero to Donald Trump voters—in other words, a high-profile spokeswoman. But there’s a deeper role she hasn’t gotten much credit for: a principal architect of the theory behind Trump’s winning campaign.

Years before Conway went to work on Trump’s campaign—when she was still a midlist conservative pollster and Steve Bannon was still running Breitbart—the two were charter members, Bannon recently told me, of the “cabal” he was forming behind the scenes to upend the Republican establishment. And Conway’s ideas were the key to a major shift in the way Trump addressed immigration, which became his signature issue.

One Conway poll in particular—a little-noticed 2014 messaging memo commissioned by a controversial anti-immigration group—Bannon cited as a sort of Rosetta stone of the message that powered Trump’s victory. It was, Bannon told me, a pillar of “the intellectual infrastructure of the populist movement that candidate Trump galvanized” from the moment he began his candidacy in 2015.

Conway’s role in shaping Trump’s political strategy is among the themes of my profile of her in The Atlantic’s April issue, and it bears a deeper look. She played a key part in shaping the counterintuitive political theory—dismissed at the time by both Republicans and Democrats—that ended up putting Trump in the White House. That makes Conway a central figure in the political realignment Trump pulled off in 2016, far more than the mere talking head many take her for.

* * *

The story begins in the aftermath of the 2012 election, which Mitt Romney lost after receiving just 27 percent of the Hispanic vote. The Republican National Committee responded with a now-infamous report that’s come to be known as the “autopsy,” which urged the party to rebrand itself with women, young people, and minorities, or face a demographic death spiral. It made only one policy recommendation: to attract Hispanic voters, the party must embrace immigration reform.

Romney had taken a hard line on immigration, at one point urging “self-deportation”—that is, making it harder for undocumented immigrants to work in the U.S. so they would willingly return to their home countries. Post-election, commentators across the political spectrum blamed Romney’s loss on this stance.

One such commentator was then-reality-TV-star Donald Trump. “He had a crazy policy of self deportation which was maniacal,” Trump told the conservative website Newsmax. “It sounded as bad as it was, and he lost all of the Latino vote. He lost the Asian vote. He lost everybody who is inspired to come into this country.”

The effort to get Republicans behind immigration reform almost worked. In the Senate, a bipartisan “Gang of Eight,” including Marco Rubio, drafted legislation that was backed by a broad coalition, from the Chamber of Commerce to the AFL-CIO. It passed the Senate with 68 votes, including 14 Republicans.

But it still had to get through the House of Representatives. Aware that Republican members of Congress feared a backlash from their base, immigration reformers labored to convince them that reform was politically popular—and that it was the only way for the GOP to have a prayer of winning another presidential election.

In 2014, FWD.us, the immigration-advocacy group backed by Facebook founder Mark Zuckerberg, recruited a who’s who of prominent Republican pollsters to make the reform-or-die argument, in a last-ditch push to get reform legislation through the House. The 10 pollsters concluded that supporting the Gang of Eight bill would help Republicans with swing voters without hurting them with their base. “Supporting this new immigration reform proposal should be good electoral politics for Republicans,” they wrote in a joint memo. One of the 10 was Kellyanne Conway.

The report was scheduled for release to the media on June 11, 2014. On June 10, a political meteor hit: Then-House Majority Leader Eric Cantor was defeated in his Republican primary by a little-known challenger who had hammered him for being soft on immigration. Any hope for immigration reform died that day. Many Republicans worried their party’s 2016 presidential hopes had died, too. Without immigration reform, the head of the Chamber of Commerce said, the party might as well not bother to run a presidential candidate at all.

* * *

The FWD.us poll was not Conway’s first work on immigration—she had been researching voters’ attitudes on the subject for decades. But she was generally on the other side, working for some of immigration reform’s most extreme opponents, and arguing that Republicans’ political success would come from taking a harder, not softer, position.

Since the 1990s, Conway had conducted polling for the Center for Immigration Studies, the Federation for American Immigration Reform, and NumbersUSA, all of which advocate for reducing immigration levels. The Southern Poverty Law Center refers to the troika as “the nativist lobby”—an accusation the groups strongly dispute. Though many in the D.C. consultant class consider these groups too radioactive to work with, they have formidable grassroots support across the country.

As a pundit, too, Conway had long argued that Republicans could win votes with a hard line on immigration. In a 2006 blog post at National Review Online, for example, Conway wrote that immigration was “a dominant issue on talk radio and around kitchen tables in many areas” that was “all but ignored by both political parties.” Her polling, she wrote, found overwhelming support for a policy of “tighter border security and stricter enforcement of current immigration laws to encourage illegal immigrants to go home over time”—essentially, self-deportation.

Fast-forward to August 2014. Just two months after signing onto the Zuckerberg group’s Republicans-must-reform-or-perish memo, Conway came out with a new poll that seemed to make the opposite argument. There was, she wrote, “strong consensus on many populist immigration policies,” including enforcing current immigration law, limiting illegal immigrants’ access to welfare and work, and reducing legal immigrants’ ability to bring family members to the United States.

The issue, she wrote, should be framed in terms of “America First,” and as a matter of “fairness … to blue-collar workers.” Three-quarters of likely voters, she pointed out, wanted more enforcement of current immigration laws. (Most economists agree that low-skilled immigration displaces some native-born workers while improving the economy and creating more net jobs overall. And while majorities of voters of both parties consistently oppose deporting the undocumented en masse, majorities generally also oppose increasing the number of legal immigrants.)

Conway told me her argument was intended as an explicit rebuttal to the “autopsy” report. “Candidates had been told after 2012, because Mitt Romney only got 27 percent of the Hispanic vote, that they had to support comprehensive immigration reform,” she told me. “We were telling them, ‘That’s not true.’” Non-college-educated white voters, in particular, supported the idea that illegal immigration was hurting their ability to find work, she said.

Conway made an effort to get her poll noticed, but it surfaced in the media only in an article in Breitbart (which hailed it as a “blockbuster”) and a Politico Pro article available only to paid subscribers. She personally handed a copy to Ted Cruz, and discussed it on a panel at the Heritage Foundation. At a private meeting of big GOP donors in Chicago, she urged adoption of the anti-immigration message. But the donors didn’t want to hear it, as Conway later told The New York Times: “They wanted labor and they wanted votes.”

Interestingly, while it was Conway who first told me about her 2014 poll, she was cagey about who had sponsored it. Her own company’s name was on the polling memo, and when I asked her who paid for it, she said it was “Creative Response Concepts”—the full name of a prominent conservative public-relations firm better known in D.C. by its acronym, CRC. But who was paying CRC? I called NumbersUSA, a CRC client, and got the answer: “That’s our poll,” the group’s executive director, Roy Beck, said proudly.

NumbersUSA advocates dramatically reducing legal immigration levels and cracking down on undocumented immigrants’ employment. Its positions are diametrically opposed to those of FWD.us. That Conway took a paycheck from both groups within months of each other was surprising—like advising Planned Parenthood one day and National Right to Life the next.

When I asked Conway about the apparent contradiction, she said she had participated in the FWD.us group in an effort to “improve on the questions being asked and the assumptions being made.” It was the NumbersUSA poll, she said, that better reflected her views: “The second effort was a much more comprehensive body of qualitative and quantitative work.”

* * *

One person who noticed Conway’s August 2014 poll was Bannon, who at the time was the CEO of Breitbart. Bannon had also been pondering another counterargument to the “autopsy” theory: the work of Sean Trende, a respected elections analyst for RealClearPolitics, who had dived into the 2012 numbers and come up with a different conclusion than the RNC’s.

White working-class voters, Trende found, had stayed home in large numbers in 2012—particularly “downscale, Northern, rural whites,” who likely saw no appealing option between the “urban liberal” Barack Obama and the “severely pro-business venture capitalist” Romney. Immigration reform might be good policy, he wrote, but there was a path to victory for Republicans that didn’t require more Hispanic votes: they could instead find a way to bring back the “missing white voters.”

Trende’s theory was descriptive, not prescriptive. But when Bannon put it together with Conway’s research, it suggested a political formula: a presidential campaign targeting working-class whites, with a message spotlighting opposition to immigration. Bannon framed it as remaking the GOP into the party of the American worker, the “forgotten man”; less sympathetic observers have termed it white identity politics. (Trende, for his part, told me he never envisioned his theory being used in this way.)

Trump launched his campaign with a tirade about Mexican drug-dealers and rapists (possibly inspired by Ann Coulter). This wasn’t quite what NumbersUSA wanted to hear—the group’s focus is on jobs. Early in his candidacy, Trump earned a C-minus on the report card NumbersUSA maintained on all the candidates. “At first [Trump’s message] was all about crime and terrorism,” NumbersUSA’s Beck told me. “But he just kept improving, focusing his message more and more on what was good for the worker.” By August 2015, Trump had issued an immigration policy paper that strongly echoed the Bannon-Conway line.

It wasn’t just Trump. Conway’s messaging, Beck told me, “became the blueprint for any number of Republican presidential candidates” in 2015: Scott Walker, Rick Santorum, Ted Cruz—even Marco Rubio and Jeb Bush turned more conservative on the issue. Cruz (whom Conway supported in the primaries) performed a particularly conspicuous flip-flop: Having once argued passionately in the Senate for increasing visas for highly skilled workers, as a presidential candidate he called for reducing them. Advocates for immigration reform, Democrat and Republican alike, were puzzled at the time by the GOP field’s collective turn toward policies they considered general-election poison.

Within Trump’s orbit, Bannon’s “cabal” kept gaining influence. Stephen Miller, an aide to then-Senator Jeff Sessions who had been known in Congress for his work to stop the Gang of Eight bill, joined Trump in January 2016 and remains, along with Bannon, his chief ideologue and speechwriter. (On the other hand, Reince Priebus, the RNC chairman who commissioned the “autopsy,” is the White House chief of staff.) Bannon and Conway officially took the reins of the Trump campaign last August.

Bannon’s political formula worked. Trump won the election by galvanizing working-class white voters in Rust Belt states that had previously belonged to Democrats. To Conway, his victory was a vindication of her long-held theory, and a refutation of the elite consensus of both parties, particularly on immigration. “So much of what I talked about for years in the Republican Party, long before I was [Trump’s] campaign manager,” was “leveraged into a platform” by Trump, she told me. “I talked about it for years, and it’s all in the public record.”

Her insights, Conway told me, stemmed from her research, but also from her roots in rural New Jersey and her understanding of working-class people. They were people like her own mother (whom I interviewed in my profile), who never went to college and worked a night shift in an Atlantic City casino until her back gave out.

“Every time I went to a Trump rally, I saw in the faces in the crowd everybody I grew up with,” Conway told me. At rallies in Pennsylvania, “sometimes it was literally the people I grew up with.”

* * *

One conclusion to draw from all of this is that Conway is more than just a flack for Trump. There is a tendency not to take her seriously as a strategist that may have to do with her gender, as former Hillary Clinton adviser Jennifer Palmieri—no fan of Conway’s—recently told the Times: While Bannon is generally portrayed as the shadowy mastermind, Conway gets skewered as a bimbo. Yet Trump himself seems to see Conway largely as a spokeswoman: She repeatedly refused his attempts to make her White House press secretary, and she told me she makes more television appearances than she’d prefer because he likes her public advocacy.

Another conclusion is that Trump’s political strategists consider immigration restriction to be at the heart of his electoral appeal. It is the major dividing point between his philosophy and that of the erstwhile GOP establishment. Conway told me Trump had fundamentally changed the terms of the immigration debate. “The conversation before was, ‘What is fair to the illegal immigrant?’ Are you ripping families apart? Should the DACA kids stay? Should they have driver’s licenses?” she told me. “Now, the conversation is also, ‘What’s fair to the American worker?’ What’s fair to the local economy? What’s fair to law enforcement? What is fair all the way around?”

But does Trump actually believe all the words that have been put in his mouth? “No, of course not,” Newt Gingrich recently told the Washington Post, referring to Bannon’s nationalist theories more generally. “The president has a very broad sense of what he wants America to be. His philosophy is based on four basic principles: anti-left, anti-stupidity, anti-political correctness, pro-American,” Gingrich said.

Trump may be personally squishier on immigration than the ideologues writing his speeches. To the anguish of the anti-immigrant right, he has waffled on DACA, Obama’s executive order protecting young illegal immigrants from deportation. He could rescind it with the stroke of a pen, but has said he is struggling with the “very, very difficult” decision. And in a recent lunch with news anchors, he speculated about restarting comprehensive immigration reform, setting off a brief firestorm.

Trump is good at getting people to hear what they want to hear in his often-conflicting pronouncements, and immigration reformers are no exception. A prominent member of the RNC told me he still cherishes the hope that Trump will push the Gang of Eight bill, as a sort of Nixon-to-China move.

Based on the influence of people like Conway, that seems like wishful thinking. But as Trump himself said last year, when he was caught on tape contemplating a softer immigration policy: “Everything is negotiable.”