John Kelly will depart as White House chief of staff near the end of this year, President Donald Trump told reporters Saturday. The president said he would announce Kelly’s replacement in the next few days.

Kelly’s exit comes after several months of relative personnel stability in an infamously tumultuous White House. But with the midterm elections now over, resulting in Democrats taking control of the House of Representatives, Trump concluded that now was the time for a shake-up he’s long wanted.

For many months now, the relationship between Kelly and Trump had reportedly been deteriorating, and his departure has long been rumored to be imminent. For instance, on April 30, NBC News reported that, per anonymous administration sources, Kelly has called Trump an “idiot” multiple times, and has portrayed himself as the only person defending the country from disaster.

Kelly managed to hang on to the job for quite some time after that. But things didn’t get better — and CNN’s Kaitlan Collins reported this week that Kelly and Trump were no longer even speaking to each other. Beyond that, Trump was said to want a chief of staff with more political expertise to help him handle the inevitable investigations and legislative battles with next year’s Democrat-controlled House, and to prepare for the 2020 election.

Kelly’s exit brings the Trump administration to an uncertain place. In July 2017, Kelly was brought in as an attempt to bring stability to a chaotic and disorganized White House. And by most accounts, he succeeded at doing so on internal process matters.

But his legacy on larger policy matters remains uncertain — and, of course, Kelly largely failed to get the president to behave more presidentially.

Kelly’s long road from White House savior to black sheep

Trump picked Kelly, a retired Marine general, to be his secretary of homeland security, and he held that post for about the first six months of the Trump presidency. Kelly had previously headed Southern Command (SOUTHCOM), where he supervised the US military’s presence in Central and South America. And he’d frequently called for more money, supplies, and attention to the problem of refugees and drugs coming into the US from Latin America.

Kelly didn’t particularly distinguish himself with major policy achievements during his brief stint at DHS. He did become the face of the administration’s immigration policy and distinguish himself as a staunch defender of the president and his agenda on Capitol Hill and in the media. As Vox’s Dara Lind wrote at the time, “Kelly spoke — and to all appearances believed — as if the Trump administration was a constant war against the forces of lawlessness and disorder.”

By late July, Trump had tired of his first chief of staff, Reince Priebus. The former RNC chair was widely viewed as weak and ineffective in the role, hemmed in both by rival advisers and by Trump’s own family, and never truly respected by the president himself. The embarrassing failure of Obamacare repeal legislation in the Senate proved the final straw, and Trump suddenly announced via tweet the following afternoon that Priebus was out — and Kelly was in.

I am pleased to inform you that I have just named General/Secretary John F Kelly as White House Chief of Staff. He is a Great American.... — Donald J. Trump (@realDonaldTrump) July 28, 2017

It was in some ways a surprising choice, since the former general had little experience with politics and little apparent interest in domestic issues. But Trump had concluded that he had to do something about the White House chaos, that Priebus was “weak,” and that replacing him with a tough guy general would be good — or would at least look good.

Kelly tried to change the White House process — not to change Trump, or his views

Kelly saw his first order of business as installing a more rigorous process and structure to the infamously chaotic White House. He saw no use for bombastic, Machiavellian advisers like Anthony Scaramucci and Steve Bannon, both of whom he pushed out within weeks. Others who stayed in the White House saw their access to the president restricted or their responsibilities reduced. And the frenzy of backbiting leaks among White House aides that characterized the administration’s beginning did indeed subside somewhat.

But the chief of staff’s new and improved bureaucratic process had little effect on Trump’s use of his Twitter account or tendency to cause controversy with his own statements. In fact, the first few weeks of Kelly’s tenure saw both Trump’s threat to meet North Korea with “fire and fury” and Trump blaming “both sides” for violence at a white supremacist demonstration in Charlottesville, Virginia.

There’s a larger point there: While Kelly did get credit for stabilizing the White House’s internal functioning, one thing he didn’t do — and really, didn’t even try to do — was change the president.

In fact, it soon became clear that those hoping Kelly would be a mainstream, establishment figure who’d help moderate the administration were sorely mistaken. In his hardline views on immigration, his traditionalist instincts on cultural issues, and his willingness to compromise the Justice Department’s independence, Kelly turned out to bear a great deal of resemblance to Trump himself.

On immigration, Trump is still in a standoff that he caused when choosing to wind down the Deferred Action for Childhood Arrivals (DACA) program, while calling on Congress to help the program’s recipients. And by some accounts, Kelly has been a major obstacle to a DACA deal, by demanding far greater concessions from Democrats than even many other Senate Republicans want. No deal has yet been reached, and the fate of hundreds of thousands of DREAMers hangs in the balance.

Kelly’s traditionalist and culturally conservative instincts also turned out to match Trump’s quite closely. For instance, he praised Confederate Gen. Robert E. Lee as “honorable” and said the Civil War was caused by lack of “compromise,” complained that women were no longer held “sacred” as they supposedly used to be, and said that unauthorized immigrants who were eligible for DACA protections but didn’t apply for them were “lazy.”

And Kelly seemed to be largely supportive of Trump’s efforts to undermine the Justice Department’s independence. Bloomberg’s Jennifer Jacobs reported that in January, Kelly repeatedly reached out to Justice officials to “convey Trump’s displeasure and lecture them on the White House’s expectations.” For instance, when a Justice Department official released a statement saying it would be “extraordinarily reckless” to release the Nunes memo, Kelly criticized DOJ officials for saying so.

In return, Trump stood by Kelly through a scandal that could have ended the career of a chief of staff in another administration — the allegations of domestic abuse by Rob Porter, Trump’s staff secretary. The 40-year-old aide had been a crucial ally of Kelly’s in his effort to install more rigorous processes so that the flow of documents and information to Trump could be better controlled. Indeed, Kelly kept on granting him greater authority — Porter began taking on more of a policy role, traveling with the president and helping write the State of the Union address.

But it turned out that Kelly had known for months that Porter’s two ex-wives had accused him of domestic violence — and, importantly, that this had prevented him from getting a full security clearance from the FBI. Meanwhile, the story top White House officials gave about what they knew about Porter and when they knew it kept changing.

Yet Kelly held on after that, for many more months. The resolution of the midterms, however, finally appears to have finally spurred Trump to make a change — as he now is tasked with working with a Democratic House, and as his own reelection is looming.