Chaos seems to dominate President Trump’s White House. From Omarosa Manigault Newman’s secret audio recordings to the anonymous New York Times op-ed, reports from White House officials highlight the dysfunction that has plagued the Trump administration in its first 20 months.

Nearly 200 years ago, Democratic President Andrew Jackson’s White House witnessed a similar situation: a president consumed by conspiratorial thinking, a Cabinet feeling the brunt of the president’s paranoia and accusations of an ambitious vice president waiting to step in for a president who failed to deliver on his promise of democratic populism.

The thread that links the chaos in both administrations is the emphasis on loyalty. Throughout his life, Jackson held positions that demanded loyalty — from the soldiers he led, the enslaved people he owned and the relatives and friends he mentored. Disloyal actions led Jackson to cast aside members of his inner circle. And the political consequences of these falling-outs were significant, helping to shape the two-party system and contributing to the regional strife that eventually produced the Civil War. Similar situations in the Trump orbit also could have serious long-term ramifications.

Jackson assumed office in March 1829 promising to execute the will of the people. Very quickly, however, he became obsessed with the personal dynamics of his White House staff. No one caused quite as much controversy as Secretary of War John Eaton and his wife, Margaret O’Neale Timberlake. The couple was unpopular. But despite rumors that their marriage had begun with an affair that ended with the alleged suicide of Margaret’s husband, Jackson rewarded Eaton for his loyalty.

Over the next two years, that decision came to haunt Jackson. The wives of other Cabinet members refused to associate with Margaret Eaton. They declined to visit her in her home and avoided or snubbed her at official and unofficial state dinners. Members of Jackson’s own family, including his nephew and niece, Andrew Jackson Donelson and Emily Donelson, begged their uncle to rid himself of the Eatons, to protect both his presidential agenda and his political legacy.

These decisions infuriated Jackson. His late wife, Rachel, who died less than three months before he assumed the presidency, had been the subject of character attacks during the campaign. With Rachel’s death fresh on his mind, Jackson was in the mood to defend female virtue.

The new president unleashed his fury on those closest to him. Jackson called meetings to lecture his Cabinet heads on Margaret Eaton’s virtue and John Eaton’s honor. He sent advisers to scan hotel registries for proof of the couple’s extramarital rendezvous and interview witnesses to their alleged affair. He scolded the Donelsons for allowing themselves to be manipulated and sent them back to Tennessee until they complied with his demands to treat Margaret better.

From the beginning, Jackson suspected that someone in his inner circle was using the Eaton affair to plant seeds of doubt about his competency. He quickly landed on Vice President John C. Calhoun as the villain. Even though the two had joined forces to defeat John Quincy Adams’s bid for a second term in the 1828 campaign, Jackson was justified in doubting Calhoun’s devotion.

First, the South Carolinian had previously lied to Jackson. Calhoun had also anonymously authored texts in 1828 that claimed for states the right to nullify unconstitutional federal laws — a challenge to Jackson’s belief in the permanency of the Union. The most obvious reason, however, was that Calhoun had a record of working against a president. When Calhoun served as vice president in the previous administration, he had undercut Adams to advance his own interests. If anyone in his administration could not be trusted, Jackson thought, it was his own vice president.

Ironically, Calhoun did not play much of a role in the early months of the Eaton affair, but the episode exposed the deeper conflict between the president and vice president over the issue of states’ rights. At an April 1830 celebration of Thomas Jefferson’s birthday, Jackson gave a toast emphasizing the Union, while Calhoun responded with one stressing states’ rights. A newspaper battle soon erupted, leading to Calhoun’s permanent estrangement from Jackson.

The Eaton affair, which began as a test of personal loyalty to Jackson, came to an end in 1831. John Eaton and Secretary of State Martin Van Buren offered to resign to allow Jackson to call for the resignation of his entire Cabinet so that he could bring in one more personally loyal to him. There were heated discussions among the Cabinet heads about whether they would comply with the president’s wishes, especially over what many considered a private disagreement. Nevertheless, the overhaul took place. With Postmaster General William T. Barry as the sole survivor, Jackson’s Cabinet had a whole new look just two years into his first term.

Two significant consequences of the Eaton affair show how Jackson’s emphasis on loyalty produced political reverberations felt for decades. Van Buren replaced Calhoun on the 1832 Democratic ticket, serving as Jackson’s vice president during his second term and eventually winning the presidency after Jackson’s retirement in 1837. But Van Buren’s inability to grapple successfully with the economic depression that roiled his administration strengthened the emerging Whig Party and solidified the two-party system that still exists. Calhoun, meanwhile, became the leading statesman for states’ rights and helped increase the radicalization of that movement in the decade preceding the Civil War.

Roger B. Taney, who replaced Attorney General John M. Berrien, supported Jackson’s economic policy during the Bank War of his second term. When the Senate refused to confirm Taney as treasury secretary, Jackson found another way to reward him for his loyalty. He appointed Taney chief justice of the U.S. Supreme Court, a position he held for 28 years. During his time as chief justice, Taney’s decisions echoed the proslavery views that he had articulated during his time as Jackson’s attorney general. Taney’s most famous opinion, in the 1857 Dred Scott case, helped set the stage for the Civil War.

Loyalty, more so than competence or capacity, guided Jackson’s selections. These negative ramifications demonstrated the perils of that sort of hiring process.

Stephen K. Bannon recently advised his former boss to “do what Andrew Jackson did” and root out the conspirators behind the anonymous op-ed criticizing the president. While following his recommendation might be the best course of action for Trump, as Jackson’s presidency shows, there is no guarantee that it is the best choice for the nation.