Department of Homeland Security Secretary Kirstjen Nielsen has become Trump’s immigration scapegoat — which generates friction between the president and his chief of staff, John Kelly, who is extremely close with her and believes his criticism of her is unwarranted and misplaced.

The bottom line: From when Nielsen was first nominated as secretary of homeland security, Trump had misgivings. I’ve learned that Trump even threatened to pull Nielsen’s nomination in a heated Oval Office meeting the week after she was nominated. Trump had been watching several Fox News personalities, including Ann Coulter, rip Nielsen as soft on the border. And as the Washington Post first reported, Trump claimed not to have known that Nielsen worked for George W. Bush, who he views as worse than most Democrats.

Kelly was standing up in the Oval and left the room visibly agitated, according to sources with direct knowledge. As Kelly was walking out he said, “Maybe I should just quit then.” Kelly stood by Nielsen, she got the job, and it doesn’t seem to be in jeopardy.

Since then, she’s taken on an unforgiving role: having to shoot down the president’s frequently unvetted immigration enforcement ideas (including a recent suggestion to send active duty military — not simply National Guard — to the border.) A senior administration source said some of Trump’s unvetted ideas are coming from people outside the White House, including Fox News personalities. The source added that Nielsen fully supports the president on the wall and on closing loopholes, but often had to be “Ms. No.” Trump was being fed legally unvetted ideas that would look flashy on TV but are of dubious operational value.

Kelly has been trying to direct Trump’s ire away from Nielsen and toward Congress, according to sources with direct knowledge.

The result: Trump lashes out at Nielsen and blames her — as well as Congress — for the uptick in illegal crossings of the southern border. There’s no empirical reason to think Nielsen has done anything to cause more illegal immigration — violence in Mexico is a likely culprit and the administration has argued that congressional inaction is to blame as smugglers and others feel emboldened after an initial "Trump effect." But Trump sees the bad numbers and recalls that the influx of illegal immigrants was going down when Kelly ran DHS.

What’s next: The administration is putting together a legislation package to see to address the loopholes in the system and the failures at the southern border.