The left was stunned by the announcement that Justice Anthony Kennedy, one of the decisive swing votes on the Supreme Court, will retire next month, opening yet another lifetime appointment for Donald Trump to fill. “The timing,” as constitutional law professor Jonathan Turley said shortly after, “could not be worse for the Democrats”: with the Supreme Court filibuster a thing of the past, and at least two and a half years until Trump leaves office, Democrats have virtually no options to prevent the president from naming whichever candidate he likes. “Things look pretty bleak,” another legal expert told me.

Inside the White House, however, news of Kennedy’s retirement didn’t come as a shock. In fact, as The New York Times reports, the 81-year-old’s announcement was the culmination of a carefully orchestrated 17-month campaign by the Trump administration to remake the Supreme Court before the 2018 midterms, when there is an outside chance that Republicans could lose their majority. For conservatives, Kennedy’s seat was seen as one of the keys to rolling back abortion rights—on the campaign trail, Trump pledged to appoint a justice who would overturn Roe v. Wade. But first, Trump had to demonstrate to Kennedy that he could be trusted to nominate quality jurists to the Supreme Court. The campaign was multifaceted: over the course of several months, Trump systematically nominated three of Kennedy’s former clerks for plum judicial posts. While he criticized other, more conservative members of the court, he lavished praise on Kennedy—despite the fact that the justice has been pilloried by the right for his votes on social issues. And he cultivated a relationship with Justice Kennedy’s son, Justin, who worked closely with the Trump Organization in his role at Deutsche Bank as the global head of real-estate capital markets, according to the Times.

The overtures continued outside the White House. Ivanka Trump reportedly took Kennedy to lunch shortly after the inauguration and brought her daughter Arabella Kushner to the Supreme Court to hear oral arguments as special guest of Kennedy shortly after. Republican Senator Chuck Grassley, who serves as chairman of the Senate Judiciary Committee, went on conservative commentator Hugh Hewitt’s radio show last month to implore the court’s aging judges, “If you’re thinking about quitting this year, do it yesterday.”

Perhaps most important, Trump used the nomination of Neil Gorsuch to demonstrate to Kennedy how his own legacy could be preserved. He ensured that Kennedy was involved in swearing in Gorsuch, who used to clerk for him—something that gave Kennedy “virtually parental pride,” Turley told me, describing Kennedy’s obvious delight at the ceremony’s after-party. After Gorsuch was sworn in, the White House made sure to float two more potential Supreme Court candidates—Judge Brett Kavanaugh of the United States Court of Appeals for the District of Columbia Circuit and Judge Raymond Kethledge—both of whom also clerked for Kennedy.

“I think the Gorsuch nomination was reassuring,” Turley explained. “I think it gained him a level of trust with Trump that he could discern a quality nominee, that he could find a quality nominee that could also fulfill his pledge to appoint a conservative nominee. I think the Gorsuch nomination had a huge impact on Kennedy and if I was to point at anything explaining the timing [of Kennedy’s retirement], I would probably have to say it was the Gorsuch nomination.”

For Trump and the Republican Party, winning Kennedy’s trust paid off. “The promise that [Trump] made the most often was to put a reliably conservative jurist on the court. Everyone understood that to be about Kennedy,” Turley said. “So we have every reason to expect that he will select someone more conservative than Kennedy.”