Over the past month, hundreds were killed in attacks attributed to ISIS and its inspired supporters in the United States, France, Germany, Turkey, Saudi Arabia, and elsewhere. The latest attacks, including the Bastille Day truck massacre, remind that while the group is losing territory, it is not necessarily weakening as a threat.

To make real headway in the evolving fight against ISIS, analysts and practitioners must focus on the local politics that drive individuals to go fight for ISIS – starting with the ones that make it all the way to Syria and Iraq. I analyzed ISIS enlistment files and the personal information volunteered by foreign fighters to ISIS officials in over 3,500 leaked registration forms. Here’s what I found.

Of all the information contained in this study, one narrative stretches across nearly every province with a high rate of joiners as a proportion of its local population: recruits join ISIS in regions with varied histories of resisting the influence of state institutions. Qassim (Saudi Arabia), Derna (Libya), Xinjiang (China), North Governorate/Tripoli (Lebanon), Sidi Bouzeid and the Tunisian heartland – nearly all of the “high priority” provinces identified in this study – have long been frustrated by relationships with their respective federal governments.

More than 95 percent of those who joined ISIS from China between mid-2013 and mid-2014 come from the country’s western Xinjiang province, where there are significant economic disparities between Han Chinese and local Uyghur Muslim populations, substantial state police presence, and extensive restrictions on Islamic practices such as growing beards or wearing hijabs. Residents in Derna, Libya, which had the highest rate of ISIS recruits indexed to its population of any province in the study, have long supported a local Islamic insurgency at odds with the federal state. In the late 1990s, the entire town was put under curfew for supporting the Libyan Islamic Fighting Group. In 2011, it declared an Islamic caliphate while the rest of the country was fighting Gaddafi. Today, the town is fought over by militants linked to ISIS and those supporting al Qaeda.

Yet these local challenges to governance and the other factors driving ISIS recruitment manifest differently in different countries. Tunisia and Saudi Arabia are two of the countries providing the most fighters to ISIS in the world, but the nature of the threat in these two countries is different: whereas three provinces in Saudi Arabia comprise 2/3rds of the total number of foreign fighters in the sample - Riyadh, Qassim, and Mecca - the threat of foreign fighters in Tunisia is much more diffuse. In Tunisia, the top eight provinces combined do not even reach 67 percent of the total number of Tunisian fighters. This suggests a more targeted approach to tackling the drivers of foreign fighters in Saudi Arabia and a more country-wide approach to the problem in Tunisia.

In some places where violent extremism is already a way of life – such as Derna in eastern Libya – the problem is generational. In other locations, such as Tunisia, the phenomenon of violent Islamic extremism is newer, suggesting that subnational interventions may be able to prevent the spread of the ideology before it takes root.

The need for a more nuanced understanding of this problem is urgent, because with ISIS losing territory in Syria and Iraq, reports indicate that many foreign fighters are trying to return home. The war is evolving from a battle over territory, predominantly in Syria and Iraq, to a decentralized fight against former “foreign fighters” who are committed to continuing the battle in their home countries. By learning where to look, we can start to contextualize the problem before it requires bombs and bullets to stop. In order to solve the problem as peacefully as possible in the fighters’ home countries, we need to understand what it was that drove them to leave in the first place.

CORRECTION: This article was corrected to accurately state Xinjiang province is a western province, not eastern.

Nate Rosenblatt is an analyst with nearly a decade of field-based research in the Middle East and a rising MSc student in social anthropology at Oxford University. His Twitter handle is @NateRosenblatt.