Sweden, the latest European country to fall victim to a terrorist attack, has long been known for its generous immigration policies.

In 2015, at the height of the refugee crisis, Sweden took in more migrants per capita than any other European country. That year, more than 162,000 people applied for asylum in Sweden, including 51,000 Syrians seeking protection from terrorism and the country’s civil war.

For comparison, the United Kingdom received 39,000 asylum applications in 2015, while France received 71,000 applications.

“In general terms, Sweden has a reputation as being a safe haven for people in need of protection,” said Bernd Parusel of the Swedish Migration Agency, in an interview with The Daily Signal. “And that has certainly made the country very attractive to people seeking protection. But the situation in 2015 was extraordinary and overwhelming in many ways.”

The government in Sweden, a small Scandinavian country of 10 million people that has been resettling refugees through the United Nations since 1950, reacted swiftly to the crisis, enacting a series of restrictions to its refugee and asylum policies in late 2015 and 2016.

These actions came long before the April 7 terrorist attack, in which an Uzbek man—who was a rejected asylum seeker—is suspected of driving a stolen beer truck into a crowd of shoppers, killing four people and wounding 15 others.

‘Complicated’ Counterterrorism Efforts

Magnus Ranstorp, the head of terrorism research at the Swedish Defense University, says that roughly 12,000 rejected asylum seekers have gone underground, and not returned to their home countries, including 3,000 in the Stockholm region, where this month’s terrorist attack occurred.

The suspect in the attack, Rakhmat Akilov, 39, had applied for permanent residency in 2014, and the Swedish Migration Agency denied his application in June 2016.

In December, he was given four weeks to leave the country, but eluded the grasp of authorities, despite being on their radar as a potential security risk. He provided an inaccurate address for himself.

“We had problems with our counterterrorism efforts before the asylum issue, but this has complicated it,” Ranstorp told The Daily Signal in an interview. “Because you have a lot of people who come in who will not be allowed to stay, and that in itself creates a pool of people who will try to elude themselves from the authorities. They become a shadow population with no rights. And that fuels extremism in all different directions.”

Ranstorp says that about 150 Swedes have returned from Syria or Iraq after fighting with the Islamic State, the terrorist group also known as ISIS. He said there’s no mechanism to connect those individuals with prevention and deradicalization services, and it’s difficult to punish them because of weak sentencing laws.

“Extremists meet little resistance in Sweden,” Ranstorp said. “It’s not that security services and police are not doing their work. The reason is our counterterrorism laws are difficult to apply. You actually have to prove a violent crime was committed or about to be committed [to be convicted of a crime]. It’s not enough that you joined ISIS.”

‘Generous Policies’

Ranstorp is wary about making a direct connection between the terrorist threat and Sweden’s asylum policies.

But the Stockholm attack has renewed attention on the policies of European countries such as Sweden and Germany that took open-door approaches to the refugee crisis, and are now dealing with aftershocks, even after imposing restrictions later on.

As immigrants fleeing war and poverty in the Middle East and Africa took dangerous journeys to Europe with increasing frequency over the last few years, Sweden quickly became a preferred destination.

Until recent policy changes, all asylum seekers in Sweden who were granted full refugee status received a permanent residence permit—meaning they are indefinitely allowed to stay in the country. Syrians, facing the most desperate of circumstances, got even better treatment, earning permanent residence no matter the form of protected status they sought.

In Sweden, asylum seekers are provided lodging if they need it, although, at the height of the crisis, migrants were housed in locations such as schools due to shortages of shelter.

Asylum seekers also have access to free health care, and receive cash stipends for food and necessities.

If their claims are recognized, refugees and migrants provided other forms of protection can participate in a two-year integration program that offers language classes, help finding a job, and a monthly stipend.

“There was concern in Sweden that their generous asylum policies were a pull factor for people to try to come to Sweden, especially as opposed to other countries in Europe,” said Susan Fratzke, an analyst at Migration Policy Institute who studies European Union asylum policy, in an interview with The Daily Signal.

Fratzke noted that Sweden’s generous policies cannot totally explain the strong demand from prospective refugees and asylum seekers. Sweden has an established diaspora population of certain populations, such as Afghanis, which encourages family members to try to reunite with them.

Indeed, she said, unaccompanied children from Afghanistan have ranked as one of the largest groups of migrants to seek protected status in Sweden over the last few years. More than 41,000 migrants from Afghanistan applied for asylum in 2015, making it the second-largest country of origin.

‘Reacted Quickly and Drastically’

Still, in response to the increasing demand, Sweden introduced border security measures and made its asylum offerings less generous.

In November 2015, Sweden introduced border checks with its neighbors for the first time in 20 years, requiring police to monitor trains and ferries and turn back those who don’t have valid travel documents. Under the previous system, asylum seekers could enter the country unobstructed, regardless of whether they had travel documents, like a passport.

Later, in June 2016, Sweden toughened the rules for migrants seeking asylum, limiting who can receive permanent residency, and making it more difficult for parents to reunite with their children.

Under the new policy, most refugees and migrants granted other forms of protected status receive three-year temporary residence instead of permanent residence.

“There was a feeling the situation was about to get out of hand, which is why the government and opposition worked together and reacted quite quickly and drastically to reduce the numbers coming in and to make Sweden less attractive as a destination,” Parusel said.

The measures have had an impact, at least to some degree.

According to the Swedish Migration Agency, 5,677 people applied for asylum in Sweden during the first quarter of 2017, compared to 9,145 in the first quarter of 2016 and 13,053 for the same period in 2015.

At the peak of the crisis in 2015, more than 39,000 individuals applied for asylum in Sweden in just one month (October).

“It’s hard to say what caused the decline in asylum claims in 2016, and this year, in Sweden,” said Fratzke, who also credited action by other European countries with the falling numbers, and a broader European Union agreement that returned asylum seekers to Turkey. “The decrease in the number of arrivals came pretty closely after Sweden introduced the border check measures, but other European countries also imposed their own border security policies.”

Challenges Remain

Despite these changes, Sweden faces ongoing challenges.

Parusel and Fratzke say that it’s difficult to address the problem of rejected asylum seekers staying in the country, as the suspected assailant in this month’s terrorist attack did.

That’s because many countries refuse to take their nationals back. The U.S. also faces this problem.

>>> How Other Nations Stop US From Deporting Criminal Illegal Immigrants

In addition, just like in the U.S., immigration authorities challenged by limited resources prioritize the types of people they seek to deport, and use their discretion to leave others alone.

With general elections set for Sweden next year, and the far-right, anti-immigrant Sweden Democrats party on the rise, immigration and counterterrorism policy promises to dominate the conversation.

“After the terrorist attack, many people are saying we must not change the way we live in Sweden, and keep our open attitude to the world, including towards immigrants,” Parusel said. “On the other hand, I see no way for Sweden to go back to its previous generous immigration policy.”