Libya is a mess. The country’s two competing governments—the secular-leaning House of Representatives (HoR) and the Islamist-leaning General National Congress (GNC)—have been squabbling over power since June 2014. Both sides have relied on a loose alliance of militias for support, but, mostly, those are tails wagging the dogs. These parliaments lack legitimacy or real power, and it is the militias, which prop them up, that are actually controlling the country.

On Dec. 23, the UN Security Council voted unanimously to accept a transition process to implement a “Government of National Accord,” effectively inserting a third government into Libya’s chaos.

Good luck with that.

Syria is also a mess. There are differences, of course, but militia rule and clumsy international attempts at solutions could result in a chaotic failed state much like the one in Libya. So we should learn from the mistakes in Libya as we try to deal with the crisis in Syria.

Lesson One: Don’t create a power vacuum in the middle of a war. While the current U.S. administration may or may not be willing to defer the question of Syrian President Bashar al-Assad’s transition, there are U.S. presidential candidates on both sides of the aisle who make it clear they will insist on Assad’s departure sooner rather than later.

It is certainly true that Assad’s brutality through the course of the war—including indiscriminate barrel bombing of areas with significant civilian presence—makes it hard, if not impossible, to imagine a unified Syria under his rule.

But if the Assad regime collapsed tomorrow, Syria would look much like Libya does today. When the strongman falls in the middle of a war—one in which both sides are made up of a patchwork of competing militias—the result is not a state under the rule of law but a conflict zone under the rule of the gun.

Just as the U.S. did with Libya’s National Transitional Council (NTC), it could boost the Syrian National Council (SNC) or some other transitional body. But doing so will not change the facts on the ground. The SNC, like its Libyan counterpart, does not control the militias that are fighting Assad.

In post-Gaddafi Libya, the various militias that had fought together against him did not remain united under the NTC or the next government’s banner. Instead, they competed with one another, and their clashes snowballed into Libya’s current civil war.

In Syria, similar conflicts already exist among the splintered brigades of the Free Syrian Army, the various Salafist militias, and others. If Assad were to fall in the middle of the war, this conflict would intensify and spread to areas such as Damascus, Latakia, and elsewhere.

In the long run, Assad will need to go if Syria is to be unified again, but his transition from power should not come until the country is more stabilized. This stability could come by local ceasefires like the one recently reached in Homs, or by broader ceasefires backed (or imposed) by international powers.

Lesson Two: People lie—especially when money and weapons are on the line. When the U.S. offered its support to the National Transitional Council in Libya back in 2011, its members proclaimed their beliefs in democracy and pluralism, assuring outside backers that they would uphold these values.

Figures in the NTC may or may not have intended to stick to these promises, but in designing their security forces, they essentially paved the way for radical and anti-democratic groups to receive state funding and weapons.

The NTC created the “Libya Shield Forces” system, which would come to include Islamist militias such as the February 17th Martyrs Brigade, Libya Shield 1, and others. Despite claiming loyalty to the state, these militias were (and still are) loyal only to themselves, seeking to expand their power and reputation—often by nefarious means.

In 2014, a handful of these groups even formed an alliance with Ansar al-Sharia Libya, the group suspected of carrying out the September 2012 attack on the U.S. diplomatic post and the CIA base in Benghazi, and have worked closely with them ever since.

In early December 2015, members of different groups in the fragmented Syrian opposition met in a Saudi-held conference, pledging to support a “democratic mechanism” in Syria and to respect the rights of all of the country’s minorities.

Unfortunately, their declaration isn’t worth much. The conference included radical Salafist groups such as Ahrar al-Sham and Jaish al-Islam, which have tried to convince Western audiences that they are actually moderate groups and have called on Washington and other governments to arm and support them.

One of Ahrar al-Sham’s leaders wrote op-eds in The Washington Post and the Telegraph to this effect, trying to whitewash the organization’s radical ideology and violent activities. So far, the White House has ignored these calls, but there are certainly critics arguing that it should embrace these groups.

Washington supported a Libyan government that contracted its security to radical militias such as these. It even entrusted its own security in Benghazi to one of them before the 2012 attack. Going forward, the U.S. should be more cautious in interacting with these groups—directly or indirectly—no matter how polished they appear.

Lesson Three: Beware of radical groups creating strongholds. Since at least the 1980s, Islamist militias have taken advantage of and operated from Libya’s ungoverned and under-governed territory. The most notorious of these areas are the northeastern coastal city of Derna and the adjacent Green Mountains—essentially Libya’s Tora Bora.

Since 2012, groups such as Ansar al-Sharia Libya have used this region to train fighters, stockpile weapons, and conduct operations. Ansar al-Sharia Libya not only trained its own fighters here, but also appears to have trained fighters who then went abroad to become combatants in Syria or conduct attacks such as the June 2015 massacre in Sousse, Tunisia.

The Salafist militia’s footholds in Libya are not unlike the territory in northwestern Syria controlled by Salafist rebels such as the al Qaeda-affiliated Jabhat al-Nusra, Ahrar al-Sham, and others. These groups dominate the cities and countrysides of Idlib, Jisr al-Shughour, and parts of Aleppo. If their control of these ungoverned areas continues, the threat from Syria could be much greater than the threat from Libya—in part because Syria is a larger hub and attracts more foreign fighters from across the world.

Beyond this, if Salafist militias solidify their control over the territory, essentially making it permanently ungoverned space, groups could not only train fighters and stockpile weapons, they could also take advantage of northern Syria’s proximity and access to Turkey—making them more mobile and more international.

The stronger these groups become—mainly through funding from Saudi Arabia, Qatar, and Turkey—the harder it will be to unseat them from these strongholds. It has taken a harsh and polarizing military campaign by Libyan General Khalifa Hifter to try to remove Ansar al-Sharia Libya from Benghazi after it took control of the city in October 2014—a campaign that has gone on for over a year and still has yet to succeed. What kind of efforts will be required to face an entrenched al Qaeda and its allies in Syria?

Washington should pressure its allies, Saudi Arabia, Qatar, and Turkey, to stop supporting these Salafist militias before their hold on northwestern Syria is solidified.

Lessons learned? Critics are frustrated by the Obama administration’s Syria policy, attacking him for indecisiveness or lack of will to defeat Assad, but President Barack Obama seems to have learned from the mistakes of Libya.

Rather than a headlong pursuit to take down Assad, Obama seems to be mindful of the consequences of an abrupt regime collapse. Instead of arming every group that memorizes the right talking points about democracy and pluralism, the administration has tried, though in some cases unsuccessfully, to limit its support and equipment to carefully vetted rebels.

There remain areas for the administration to improve, but the lack of U.S. leadership that critics continue to decry may just be healthy skepticism and caution.

Barring some kind of miracle, the Syrian Civil War will outlast the remainder of Obama’s administration. One would hope that the next administration will be as cautious, and remember the lessons of Libya.