During a tension-filled dinner at the White House in January, after meeting the FBI director he would eventually oust for only the second time, President Donald Trump repeatedly pleaded for Jim Comey’s loyalty, as if gaining loyalty was like borrowing a pencil, something you could simply ask for.

“The President said, ‘I need loyalty, I expect loyalty,’” according to Comey’s prepared testimony, released ahead of his Thursday Senate hearing on his role in the Russia investigation. “I didn’t move, speak, or change my facial expression in any way during the awkward silence that followed,” Comey added. “We simply looked at each other in silence.”

That was only the first of several times the topic of loyalty came up between the two men, according to Comey’s retelling of their encounters. And that was only the first of several times Comey would have to find a way to duck Trump’s ask. (Trump’s lawyers deny that the President demanded loyalty of the former FBI boss.)

In some circumstances, asking outright for someone’s loyalty is a tactic that can work. Psychologists know people can have a really hard time saying no when something’s directly asked of them, particularly when the person doing the asking is in a position of power. Requesting loyalty can also be a useful sorting mechanism: Trump’s outrageous asks can help him anticipate who may actually be willing to be loyal to him. (Comey was fired a few months after that dinner, in May.)

But Trump clearly failed to win Comey’s loyalty. One reason is obvious: The FBI’s independence is sacred, and Trump’s ask of Comey was a dramatic departure from how the FBI and the president typically interact. Trump might have also misjudged Comey’s sense of duty.

But there’s more to it. We asked a few psychologists to weigh in on why Trump’s demands for loyalty failed in this case. They explained that Trump made two big mistakes.

Trump may have misjudged who Comey sees as his “in-group”

Humans have a basic tendency of sorting people into groups: us and them. Team thinking powerfully changes our perception of the world. When we perceive another as being in our “in-group,” we tend to like them more, we’re more likely to give them money, we’re less likely to empathize with their feelings. These are key components of loyalty.

And this psychological concept may explain Trump’s downfall.

Simply put: Trump misjudged which team Comey was on. Comey’s conception of loyalty is probably to the nation, the law, the constitution he swore an oath to, said Lehigh University psychologist Dominic Packer.

And even if — on some level — Comey identifies as a “Republican” (he had been registered in the party for some portion of his life), studies in psychology suggest having a strong personal identity can help buffet the tendency to fall in line.

When experimenters have group participants reflect on their own personal identities — usually via positive affirmations like writing down “I like how smart I am” — they’re less likely to exhibit partisan bias.

So if Comey is self-assured in his identity as a law enforcement officer and an independent actor, the pressures to conform to the Trump agenda will bounce off his skin.

This is like the case: “The FBI will always be independent,” Comey asserted during the beginning of his testimony Thursday.

Trump based his sense of loyalty on power — another mistake

David DeSteno, a psychology professor as Northeastern, explained that there are a couple of methods people can use to build loyalty and trust.

One is, you meet someone, work with them, and learn about whether they’re going to have integrity and cooperate with you, DeSteno said. “Trust is a bet that a person is going to hold up his end of the bargain — accept some short-term cost for longer-term gain.”

Psychological studies show this pattern often holds in human relationships. We grant power to those who are empathetic, and those who look out for the greater good. A more Machiavellian approach works, too, but it can be off-putting. “People intuitively recoil against people who look as though they will exploit others, the social collective, and undermine the greater good,” Dacher Keltner, a UC Berkley psychologist who studies power, says. “I see Comey's actions as in part guided by this intuitive tendency.“

The other way to build trust is less effective: You demand or ask for it, as Trump does. This normally doesn’t work, except for in relationships with a power differential.

“Trump is president of the United States,” DeSteno said, “so there’s a power differential, and someone who has higher power can demand, ask, or enforce trustworthy behavior on the part of another person with a sense of implied coercion.”

According to Comey’s testimony, that seems to be what was happening between the two men. Trump allegedly repeatedly mentioned the loyalty the two should share.

But there’s a problem with this kind of relationship building — and it also helps explain Trump’s downfall: It only lasts as long as that power differential is in place.

“Now that Comey is free — he has been fired — he has no loyalty or trust, there is no long-lasting relationship,” DeSteno explained.

Building trust this way may have worked when Trump was a businessman, and could fire people without repercussion. But it doesn’t jive quite the same way with government officials, who follow protocols and may have a sense of duty to the country that is bigger than any one administration.

“Trump’s tactics tend to be power based — they are coercive, and they degrade over time,” DeSteno added.

They certainly seemed to have broken down, even before Comey was fired from his post. Beyond being a remarkably day in US politics, this may also go down as a lesson in how not to build friends and influence people.