Washington — In his first month on the job, White House chief of staff John Kelly has made significant progress toward imposing discipline on a chaotic operation, even as it’s clear he still struggles to have the same effect on the president himself.

The White House is a less contentious place and decision-making is becoming more orderly under Kelly’s thumb, according to more than a dozen people interviewed by The Associated Press, including White House officials, outside advisers and others who work regularly with the administration. They say a group of more experienced advisers — including a trio of generals — is increasingly holding sway. And they describe a process in which Kelly has successfully limited dissenting voices, restricted access to the president and “stacked the deck” on major decisions to guide him toward an outcome. The new Afghanistan war strategy announced this week was a chief example of the process.

But President Donald Trump also made clear this week there’s no steering him toward less incendiary rhetoric.

“You know, they all said, Mr. President, your speech was so good last night. Please, please Mr. President, don’t mention any names. So I won’t,” Trump said. He went on to insult a pair of Republican senators without mentioning their names and then threatened to shut down the government if Congress doesn’t give him money for his border wall, much to the alarm of Republican lawmakers.

The remarks pointed to Kelly’s biggest challenge: piloting Trump though a hectic fall filled with high-stakes deadlines for funding the government, raising the debt ceiling and making progress on tax reform. It remains unclear whether Kelly’s new grip on the decision-making process will be a check on Trump’s impulses on domestic priorities that were central in his candidacy.

“Believe me, if we have to close down our government, we’re building that wall,” Trump said in Phoenix.

Kelly’s consolidation of power is a direct a result of the dramatic shakeup of Trump’s inner circle. Since taking the reins from former chief of staff Reince Priebus, Kelly has begun to reorganize the process by which Trump receives information and push back against the open-door policy that gave White House officials constant access to their boss.

“General Kelly demands of the White House staff those same qualities he has exemplified in his 45 years of public service: integrity, humility, team cohesion, focus, discipline, performance and results,” said White House counselor Kellyanne Conway. “He commands respect and shows respect, empowers us to succeed and expects us to help promote the president’s agenda and not a personal agenda.”

While Kelly has made clear that he sees his role as managing White House staff and not the president, he also helped persuade Trump to part ways with adviser Steve Bannon. The populist firebrand often goaded Trump toward some of his more nationalist policies and sharp-elbowed rhetoric and was often blamed for White House infighting.

In addition to leaning on Kelly, the former Homeland Security secretary, Trump is increasingly relying on Defense Secretary Jim Mattis and National Security Adviser H.R. McMaster, an active-duty lieutenant general, on matters extending beyond foreign policy. Mattis and Kelly are retired generals — a point Kelly underscores in meetings, where he has told Cabinet secretaries and advisers to refer to him as chief of staff rather than “General Kelly.”

The group of generals was particularly critical to the Afghanistan decision. After seven months of debate, during which the president repeatedly questioned Pentagon plans, the dynamic changed significantly in the final four days before Trump’s Monday night address to the nation, according to an official who like some of the others interviewed spoke on condition of anonymity to discuss internal deliberations. With Trump ensconced at the Camp David retreat, Kelly ensured that he heard directly from Vice President Mike Pence, Mattis and McMaster, who had warned of the consequences of withdrawal. Trump was not in contact with Bannon, an intervention skeptic, or Blackwater Worldwide founder Erik Prince, who had advocated for the use of more military contractors, the official said.

Bannon, who opposed a troop increase, did speak with Trump twice on Saturday and also with Pence during the day, according to a person familiar with the calls. By then the major decisions on Afghanistan had been reached. The person, who spoke on condition of anonymity to describe the private conversations, said the calls were cordial.

On Monday evening, Trump announced the U.S. would move additional troops to Afghanistan despite his “original instinct” to retreat from the 16-year-long war.

Kelly’s approach acknowledges that Trump is prone to soliciting advice from unusual corners and being persuaded by the last person who has his ear.

That applied to Bannon, in particular, who helped propel Trump to the White House with his unique blend of nationalist fervor, economic populism and love for bare-knuckles political brawling. He successfully pushed the president to abandon the Paris climate agreement, was particularly hawkish on both China and Iran, and had urged Trump to refuse to sign a budget bill unless it contained money for his wall.

Though Bannon’s influence had waned, Stephen Moore, an economist at the Heritage Foundation who was a senior economic adviser to Trump’s campaign, said: “I think having him in the White House was critical to Trump making the decisions he made. … He certainly was a voice in Trump’s ear, pushing him on those issues.”

Bannon left the White House and returned to his post at Breitbart News, where he has said he intends to continue to advocate for his views.

“They’re going to get a lot more attacks on the outside,” said former House Speaker Newt Gingrich, an informal Trump adviser. “In a sense, the discord has moved outside the White House.”

Still, many close to the White House say that, regardless of Kelly’s influence, Trump will not easily betray his instincts or his core political priorities, which closely align with Bannon’s.

On issues such as voter fraud and immigration, “I think Steve Bannon’s point of view is exactly where President Trump’s point of view is,” said Kansas Secretary of State Kris Kobach, who co-chairs Trump’s voter fraud commission. “So I don’t see the Trump administration changing its view or its stance at all.”