Over the past week, the Islamic State has attacked Bangladesh, Iraq and Saudi Arabia. But they’ve been particularly active in Turkey. Why does the terror organization target that country?

There are a couple of reasons. Turkey is a democratic country with a secular constitution. It’s a member of NATO, in talks with the European Union, an ally of the United States and a new friend of Israel. Even with the conservative social policies of President Recep Tayyip Erdogan, Turkey is antithetical to everything the Islamic State wants to create.

It wasn’t always this way. When the Islamic State captured Mosul, Iraq, in June 2014, it kidnapped 46 Turkish diplomats and their families.

Ankara refused to join Washington in attacking the Islamic State as retaliation. Instead, they focused on securing a release of the hostages. For months, the Islamic State kept the Turkish hostages in order to maintain this tenuous balance, and Ankara and the Islamic State entered into a “cold war.” That meant that in September 2014, the Islamic State did not overrun the tomb of Suleyman Shah (Turkish territory inside Syria guarded by a few dozen troops). In exchange, Turkey let the Islamic State use its country as a passageway to smuggle antiquities, foreign fighters and weapons.

Turkey secured the release of the hostages in September 2014. Six months later, it evacuated troops guarding the tomb, and physically moved the Ottoman patriarch to an exclave next to the Turkish border, eliminating another key vulnerability.

This changed the dynamic between the two governments. Soon after, Turkey joined the United States’ coalition against the Islamic State. Turkish planes started bombing the group’s strongholds in July 2015. Ankara also started cracking down on Islamic State smuggling routes across the Turkish-Syrian border. The government has backed Syrian rebels working to wrest control of the A’zaz-Jarablus corridor in northwestern Syria, the Islamic State’s main conduit for smuggling fighters into Turkey and beyond.

The Islamic State can’t afford to lose access to the Turkish-Syrian border. So it’s responded with multiple attacks, including the most recent strike on Istanbul’s Ataturk Airport.

No matter what Turkey does, it will be hard to stop the Islamic State in the short term. The group has networks and sleeper cells inside the country. It is also aware of weaknesses in the Turkish security system.

Long-term, I believe the country will be able to defeat the Islamic State. But Turkish success will depend on whether the country will manage to prioritize its threats right. Since the beginning of the Syrian uprising in 2011, Turkey’s Syria policy has singularly focused on one objective: ousting the Assad regime. Accordingly, earlier in the war Ankara turned a blind eye to radical foreign fighters crossing into Syria. This is not because Turkey supported radicals, but rather because it saw them as useful combatants that would usher in the fall of the Assad regime.

Ankara’s emphasis on Assad is over now. The Istanbul attack has aligned the interests of Ankara and Washington in Syria. Both now want to see the Islamic State defeated. Unfortunately, things in Turkey will likely get worse before they get better.