Former President Barack Obama withdrew troops from Iraq in 2011, but U.S. troops were still on the ground when President Trump visited on Wednesday. As Trump commits to pulling troops from Syria, he should take the lesson that such simple moves give rise to unintended consequences.

In 2011, Obama pulled U.S. operations from the country. The ensuing power vacuum gave the self-declared Islamic State the opportunity to rapidly gain ground and seize cities. Then U.S. forces returned in 2014. Now, more than four years later, the U.S.-backed coalition is still embroiled in an ongoing fight against ISIS.

During his surprise post-Christmas visit, Trump got a very brief view of the consequences of Obama's hasty departure. U.S. troops are still away from their families and still facing the threat of ISIS that was, to some extent, the product of a well-intentioned withdrawal.

During his speech to troops at Al Asad Air Base, just outside of Baghdad, Trump defended his decision to withdraw troops from Syria but offered a mixed message on the the state of the fight against ISIS.

Walking back from his earlier comments that ISIS had been defeated, he explained that troops would not be leaving Iraq and that the country could remain an important base of operations should ISIS again gain power in Syria.

He said, “If we see something happening with ISIS that we don’t like, we can hit them so fast and so hard they really won’t know what the hell happened.”

The worry about the resurgence of the Islamic State is justified. The group's leader, Abu Bakr al-Baghdadi, remains at large and as many as 30,000 ISIS fighters remain active.

But in acknowledging that ISIS remains a threat on Wednesday coupled with the yet-to-be revealed timeline on troop withdrawals, Trump also opened up a potential path forward to make good on his promise to remove U.S. forces while not repeating Obama’s mistake of a hasty cut to operations.

Instead, Trump would do well to talk up his visit to troops and discuss the ongoing challenges of ISIS while saying that the plan is to leave Syria as soon as operations are ready to be entirely supported from Iraq.

Although that plan will likely draw criticism, it would allow Trump to both pull out troops while also incorporating departing Secretary of Defense Jim Mattis’s advice and demonstrating that he truly is interested in defeating ISIS. Importantly, that revised plan would foster goodwill with our Kurdish allies, who have been instrumental in the fight against ISIS -- and felt betrayed by Trump's announcement that he would pull U.S. troops out of Syria, leaving them at the mercy of Syrian President Bashar Assad and Turkish President Recep Erdogan.

ISIS is far from defeated and Trump says he felt the danger, citing concern for first lady Melania Trump, during his visit to Iraq. That might have convinced him of what Mattis couldn’t convey: in both Iraq and Syria, a quick departure may well do more damage than good.