Yesterday’s terrorist activity in Spain and ISIS’ thus far unsubstantiated public claim that the attackers were “soldiers of the Islamic State” has once again thrust the group to the forefront of the world’s attention—a place ISIS has occupied for years now. Indeed, in the summer of 2014, I was asked during a congressional hearing whether the Islamic State (also called ISIS), which had recently seized Mosul and was threatening Erbil, could capture Baghdad. Then deputy director of national intelligence, I replied that the intelligence community did not think such a takeover was plausible given what we knew about ISIS’ personnel strength and the overwhelming Iraqi military and Shia militia presence in the city. I’m not certain my answer persuaded anyone; the anxiety about ISIS’ rapid battlefield gains, newfound ability to mass forces and strike at vulnerable locations, and acquisition of vast military hardware from retreating Iraqi soldiers was palpable.

As it turned out, ISIS was able to detonate hundreds of car and truck bombs inside Baghdad in the following years, but never posed a serious threat to the city. But the question I was asked perfectly captured the deep fear that ISIS generated in Iraq and the deep pessimism about the Iraqi government’s ability (even with U.S. military help) to defeat it.

The perception of ISIS as a military juggernaut has changed dramatically since then thanks to the progress against the group achieved through the work of two U.S. administrations; the United States’ military, diplomatic, and intelligence services; and a coalition of external partners, particularly the Iraqi military and Kurdish security forces.

A man lights a candle in an impromptu memorial a day after terrorist attack at Las Ramblas in Barcelona, Spain, August 18, 2017. Sergio Perez / Reuters Compared to its peak territorial influence in August 2014, ISIS no longer operates in more than two-thirds of the populated territory it once controlled in Iraq and Syria, and the group will likely lose its stronghold and symbolic capital in Raqqah before year’s end. At the same time, ISIS’ revenue base has been decimated, thousands of its fighters have been killed, and the number of foreign fighters flocking to the ISIS banner in Iraq and Syria reduced to a trickle. (Some estimates are as low as 50 new recruits per month.) Indeed, as the world marks the three-year anniversary of ISIS’ territorial high-water mark, it seems almost certain that its physical caliphate will soon be gone, at least for the foreseeable future.

So, what does this mean for the group’s near-term strategy and prospects, and the options U.S. policymakers might consider to further erode the group’s influence? As in the Mosul campaign, it is clear that ISIS intends to put up a tough fight for Raqqah, likely dragging out the battle for several more months. This will no doubt produce significant further destruction of Raqqah’s infrastructure and the loss of more innocent lives, but ISIS’ ultimate fate in Raqqah is at this point almost certainly sealed.

Post-Raqqah, available open-source information indicates that ISIS will likely concentrate its forces in Syria along the middle Euphrates River Valley, primarily from south of Raqqah through Dayr az Zawr and down to Al Qaim along the Iraqi border. This region is rich in oil and has been outside of Syrian government control for several years, making it an attractive fallback option for the group.

In Iraq, ISIS will likely be forced to retreat to small pockets of territory along the western border with Syria, including in Anbar, and concentrate in other areas of residual strength such as near Hawijah (a longtime ISIS stronghold located 30 miles west of Kirkuk) and around the Bayji oil fields. From these remaining redoubts, ISIS will continue to launch periodic attacks against local security forces, conduct IED attacks in and around Baghdad, and do everything possible to cow the local populations by reminding them that the group’s defeat is only a temporary setback.

On balance, then, it is quite likely that the bulk of ISIS’ remaining fighters and resources will be located in Syria by the end of this year, and that these fighters will try to entrench themselves there against what they know will be increasing pressure from either U.S.-backed forces or the Syrian regime and its Russian and Iranian allies.

Meanwhile, ISIS’ public statements and actions, possibly including yesterday’s attack in Barcelona, provide a clear road map of the group’s intentions elsewhere. Its two immediate goals are to continue trying to inspire (or at least claim credit for) terrorist attacks in the West and to simultaneously deepen the connective tissue between the group’s core and several of its foreign nodes, primarily those operating in Afghanistan (along the Pakistan border), Libya, the Sinai, and Southeast Asia (especially in the Philippines).

On the messaging front, ISIS leaders are already downplaying the crippling territorial losses the group has suffered, instead trumpeting any attacks conducted in its name, stressing the need to continue the resistance, and urging loyalists to plan for a long fight with the crusaders.

With that in mind, there are a few ways to continue degrading ISIS and counter the next stage in the group’s evolution. First, the United States needs to finish Raqqa. This is a clear goal of the Trump administration and, in my view, absolutely the right priority. Raqqah was the first major city that ISIS captured in its rise to power, is recognized by the group’s followers as the capital of the caliphate, and is reported to be a hub of external planning and operations. Seizing the city will not preclude ISIS from launching attacks in the region and especially in Europe, but it will make such strikes much harder. ISIS is adaptive and resilient, but losing the city as a base of operations will sting both operationally and psychologically since it will undermine the narrative that the group has the battlefield momentum.

Second, the United States will have to anticipate new threats. ISIS leaders undoubtedly recognize the group’s precarious military position in both Iraq and Syria and are likely spending considerable time and effort trying to devise new tactics and targets, as well as options for using existing capabilities in creative ways. Whether it’s a new use of vehicle-borne explosives or the use of drones to swarm a target (potentially a coalition aircraft), ISIS knows it needs to get creative, and the West should anticipate a range of innovative tactics from the group in the coming months. This is obviously no time to be complacent, and defense and intelligence analysts and planners will want to spend time thinking about ISIS’ “worst case” options for striking back.

The third step will be preventing the establishment of new safe havens. Given the brutal block-by-block fighting that has been required to uproot ISIS from Mosul, Raqqah, and Sirte, it’s critical to make every effort possible to preclude ISIS from seizing and establishing itself in any other major population centers. This will require U.S. intelligence, defense, and diplomatic service to focus on identifying any emerging ISIS safe havens. The United States will also have to act quickly, whether through coalition partners, local security services, or independently, if ISIS appears to be gaining traction in a major population center anywhere in the world. One clear lesson learned in the past three years is that it’s far easier to confront ISIS when it’s still trying to consolidate influence in an area and not after it has had time to establish governing institutions, terrorize the local population and force young people into its ranks, extract resources from the local economy, mine and booby trap major avenues of approach, stockpile weapons and provisions, and plan escape routes, especially for the group’s leaders.

Fourth, the United States must improve its counter-ISIS narrative. ISIS has been quite skilled at building a global brand and adapting it to shifting conditions. Good messaging will be critical to long-term success against the group (particularly the effort to drive down its appeal among young Muslims), but it is still, unfortunately, an area of relative weakness within the U.S. government. The issue has been discussed in the National Security Council for many years, and many efforts have been made to fix it. Unfortunately, the progress has still been only incremental. This is, in my view, largely because of complex (and potentially outdated) information sharing and end-use restrictions, as well as an array of bureaucratic stovepipes.

Once the United States is able to resolve this problem, however, there are a range of messaging opportunities that we might want to exploit, including the end of the physical caliphate and any accompanying religious obligation to support it, the physical devastation and human misery that ISIS governance has left in its wake (especially on local Muslim populations) from Iraq to Libya to Syria to Southeast Asia, the heroic role that Muslim defense forces have played (especially in Iraq) in defeating the group, and the impossible odds facing young Muslims trying to join ISIS anywhere in the world.

Meanwhile, the United States will also have to build partner capacity. The country obviously can’t outfit every military or security service that’s threatened by ISIS or completely rebuild every city that the group has devastated, but it would benefit from providing targeted financial and logistical support where it’s most needed. The exceptionally successful work with Iraq’s counterterrorism service is a model of productive defense cooperation, and the constant, senior-level engagement with Prime Minister Haider al-Abadi on a range of political, economic, and humanitarian issues is also worthy of emulation elsewhere. In any event, it’s crystal clear following the U.S. experience in Iraq with Prime Minister Nouri al-Maliki that disengaging and trusting only in the wisdom and spirit of goodwill and reconciliation among leaders in at-risk countries is a strategy we’d be wise to avoid.

Further, there is no more important step that could be taken to lessen the appeal of ISIS globally than for the United States to help ease the Sunni-Shia confrontation that is, unfortunately, underpinning the group’s appeal, especially among Sunni populations that feel threatened by Shia political power. Unfortunately, these tensions seem only to be growing, stoked by fears of Iran’s growing regional influence and its role in fueling proxy conflicts from Syria to Yemen. Without efforts to help foster an improvement in relations between Iran and Saudi Arabia, the United States’ ability to drain the swamp of potential ISIS recruits will be limited.

Finally, the United States needs to avoid fear. A recent Pew study found that ISIS is identified around the globe as one of the top two (along with climate change) threats to national security in the world today. In the United States, nearly three-fourths of those polled identified ISIS as a major threat to our security, compared to only 47 percent of those who felt threatened by Russia’s power and influence and 41 percent by China’s. Given the daunting military and operational challenges ISIS faces, as well as the clear and present threat Russia and China poses to the United States, it is fair to ask whether we are dealing with a case of threat inflation when it comes to ISIS. Indeed, it is not certain that ISIS is even the most worrisome terrorist group the United States faces globally, since al Qaeda and its offshoots in Syria and Yemen probably possess considerably more capability than ISIS to conduct operations in the United States.

That is obviously not to say that ISIS has been eliminated as a threat to U.S. interests, or that the country shouldn’t worry about ISIS’ ability to inspire or conduct attacks against citizens at home and abroad. Rather, it is important to place the group’s challenge in a realistic framework within which sound national security policy can be constructed.

After three years of fighting this iteration of ISIS, it’s clear that the group has been placed squarely on its back foot, that it faces enormous military and operational challenges that will be difficult to overcome, and that it’s absolutely within the United States’ ability to deal ISIS a series of additional body blows if it continues to work patiently, wisely, courageously, and in line with its values and international partners.

And whenever the group’s inevitable attacks and sheer brutality cause most of us to recoil in fear or disgust, it’s always wise to recall Winston Churchill’s observation to the Canadian House of Commons in 1941 that “We did not journey all the way across the centuries, across the oceans, across the mountains, and across the prairies because we are made of sugar candy.” Effectively countering the next evolution of ISIS’ capabilities and pernicious ideology will not be easy, but it’s certainly achievable.