On his fifth day on the job as Donald Trump's new chief of staff, John Kelly gathered about 200 White House aides for a meeting where he spelled out in blunt terms the way things are going to work in the West Wing he now oversees.

The retired Marine Corps four-star general said he didn't care whether they had been part of the Trump campaign or had joined the administration from Capitol Hill or a some other corner of the political world, according to people who attended the meeting. They all work for the president now, he told them, and they had to act as one team.

Echoing the Marines' credo of "God, Country, Corps," Kelly said he expects all of them to put country first, the president second, and their own needs and priorities last. He stressed work ethic. And he sharply warned them against leaking, an obsession of Trump's. Even if it may seem innocuous to pass along some bit of classified information to someone without a clearance, he said, it's a crime.

Since his swearing-in on July 31, Kelly has moved swiftly to bring order to a chaotic and unruly White House, according to accounts from 12 administration aides and outside observers. Now, bigger challenges lie ahead as Trump gets to work filling key administration posts, including the one Kelly just vacated.

After moving over from the Department of Homeland Security, Kelly fired communications director Anthony Scaramucci just 10 days after Trump had brought him in, and dismissed two National Security Council aides who were thought to be divisive or acting outside the chain of command.

Kelly's influence was seen in Trump's unusual late-night statement on Friday in support of his National Security Adviser H.R. McMaster, with whom he's been at odds on and off for months. Both Kelly and Trump's son-in-law and senior adviser Jared Kushner have helped shore up McMaster and resist calls for his ouster by some on the far right, who questioned the Army lieutenant general's support for Israel or decry his views as too conventional or globalist for Trump's brand. Trump backed McMaster as a #FireMcMaster campaign took flight on Twitter.

But in some ways, clarifying chains of command and offering token support for remaining White House officials was the easy part. Now Kelly must navigate a complex game of administration-wide musical chairs, figuring out how to fill not only his old job at DHS but the post Scaramucci briefly occupied leading the communications department. The task could present some of the first resistance to the military discipline he's attempted to instill within the White House, with Trump's advisers and confidants inside and outside the administration sure to have strong opinions about who would be best for each of those roles.

The search for replacements is under way even as the president undertakes what the White House has billed as a "working vacation" at his Bedminster, New Jersey, golf course. The change in venue alone could foil Kelly's efforts to assert control over the president's activities -- already, photographs have emerged on social media of the Trump on the golf course and mingling with wedding guests at the resort.

Trump resisted attempts by Kelly's predecessor, Reince Priebus, to stop White House staffers from popping in unannounced to see the president -- dropping news articles on his desk that he would love or hate, sharing ideas for tweets, or just getting valuable face time with the boss. Trump, who's known to be easily distracted, would wave in the visitors, even as his scheduled appointments sometimes backed up.

Kelly has insisted that anyone who wants to see the president must now go through him.

While Kelly isn't vetting every presidential tweet, Trump has shown a willingness to consult with his chief of staff before hitting "send" on certain missives that might cause an international uproar or lead to unwelcome distractions, according to three people familiar with the interactions. Kelly has been "offering a different way to say the same thing," one person said.

Trump has made it clear, however, that he reserves the right to ignore advice on tweets. Since joining the social media platform in 2009 he's sent over 35,000 of them. On Aug. 3, Trump lashed out at Congress for passing a bill that limited the president's power to lift sanctions on Russia. "Our relationship with Russia is at an all-time & very dangerous low. You can thank Congress, the same people that can't even give us HCare!"

Since then, most of Trump's tweets have been more buttoned down -- thanking supporters or praising himself for the strong stock market.

A White House official confirmed that Stephen Miller, the senior adviser to the president whose portfolio now includes speech-writing and immigration policy, is in the running to oversee the communications shop. Miller, 31, a combative and volatile personality who's authored some of Trump's most strident rhetoric on immigration and other issues, clashed hard with reporters at a White House briefing last week.

Tapping Miller for such a key role would suggest a departure from Kelly's stated desire to deescalate tensions with the media. Yet Miller is well liked by Kushner and senior adviser Stephen Bannon, who've seen allies purged from the White House since Kelly's arrival.

Meanwhile, Elaine Duke became acting secretary of DHS upon Kelly's departure. It's unclear how quickly her old boss will be replaced. As many as 10 men and women are being discussed within the administration as possible replacements for Kelly, including lawmakers, other cabinet members and current and former law enforcement officials.

Rep. Mike McCaul, a Texas Republican who chairs the House Homeland Security committee, is thought to be well qualified but didn't impress Trump when he first interviewed for the job, said a person familiar with Trump's thinking. Energy Secretary Rick Perry, the former governor of Texas with long experience in U.S.-Mexican border issues, told Trump and Kelly he'd prefer to stay in his current role.

Joining Kelly at Bedminster over the weekend was Rick Wadell, a deputy national security adviser and major general in the Army Reserve, and White House staff secretary Rob Porter, whom Kelly has asked to help vet documents before they reach Trump's hands.

Kelly briefed Trump twice over the weekend on the crash of a U.S. military helicopter off the coast of Australia, and the pair were in constant contact as the administration worked to secure Saturday's unanimous U.N. Security Council resolution authorizing new sanctions against North Korea, an administration official said.

Praise for the appointment of Boston-born Kelly, 67, has been swift and bipartisan.

"His influence has been felt and seen immediately," Anita McBride, a former chief of staff to first lady Laura Bush and White House personnel director who worked for nine White House chiefs of staff in three Republican administrations.

"If there's no order and process and structure in the West Wing, no president is going to be successful." That's where Kelly's long military experience and months-long tenure leading the sprawling Homeland Security agency have served him well, she said.

Leon Panetta, whom Kelly served as senior military aide when Panetta was President Barack Obama's Defense Secretary, was among the first people Kelly called when Trump named him to the White House position. Panetta, chief of staff to President Bill Clinton for 2 1/2 years, said in an interview that he shared with Kelly his view that mutual trust between the president and the chief is essential.

Panetta wasn't surprised to hear of Kelly's credo to his staff. "For a Marine general, country is always first," he said. "The key to dealing with leaks is to make clear that the staff is a team and they have to be dedicated to country and then to the president. Their loyalty has to be there first and if it is, that's the best way to take care of leaks."

Bringing the White House under control is only part of Kelly's brief. He must also quickly move to help Trump patch up his fractious relationship with Republicans in Congress, whose support the president will need in coming battles over the debt ceiling, budget and tax reform.

Kelly is widely respected on Capitol Hill but has no recent experience wrangling legislation. He spent part of his first week reaching out to GOP lawmakers, many of whom have signaled they no longer feel compelled to follow Trump's lead.

Ultimately, Kelly's success will depend on whether he continues to have the backing of his boss. Trump has contained himself for brief periods before, only to return to form. It may prove difficult for Kelly to prevail on Trump to bottle up his tweets at those who defy or criticize him -- or to refrain from expressing his outrage at the expanding investigations into possible ties between Russia and the Trump campaign, a subject that's given rise to some of his most explosive statements.

Over time, said Panetta, Trump could come to chafe at Kelly's insistence on order. "He's been able to take some important steps to improve discipline, control access to the president and the Oval Office, and develop a chain of command within the White House itself," Panetta said. At the same time, "It's just the beginning -- obviously time will tell about whether the president will continue to support those efforts."