The North African nation of Morocco is distinguishing itself through a series of successes in breaking up Islamic terror cells and foiling attacks.

As part of its systematic crackdown on terrorist activities, Morocco established its own home intelligence agency in 2015, the Bureau Central d’Investigation Judiciaire (BCJI). In less than two years, the Bureau has taken credit for uncovering 40 terrorist cells and arresting nearly 600 people.

The same year, Morocco passed a law calling for the monitoring of Moroccan travelers visiting Libya, Syria or Iraq and stiff punitive measures for anyone connected to terror groups.

According to the law, anyone trying to join extremist groups in combat zones faces a punishment of ten years in prison. The law also provides for targeting those who return to the country after having borne arms in war zones.

The 2015 stipulations were added to earlier measures adopted in 2011 giving law enforcement greater leeway when investigating terrorist activities. The measures included entering and searching premises, the seizure of documents and the detention of persons.

To show its seriousness in combatting terror, the country has also resorted to stringent measures even regarding Muslim dress.

Despite its 99 percent Muslim composition, earlier this year Morocco adopted one of the strictest burqa bans in the world. In January, the Interior Ministry of Morocco announced it had “taken the step of completely banning the import, manufacture and marketing of this garment in all the cities and towns of the kingdom.”

The ban applies only to full-face covering burqas, whereas the majority of Muslim women in the country wear headscarves without the veil, yet the move was seen as a sign of real commitment in the war on terror.

At the time, Moroccan politician Nouzha Skalli praised the ban as “an important step in the fight against religious extremism.”

One of the keys to the Bureau’s effectiveness, according to Mohammed Benhammou, an adviser to the Moroccan government on counterterrorism, is the coordination of intelligence with other countries.

Benhammou said that terrorism outside Morocco poses a serious threat for the country and thus intelligence sharing is essential. “For example, a little while ago terrorist suspects from Chad and Tangier were arrested because they were preparing attacks there,” he said. “And we share all our information with European countries, because we all have the same enemy—terrorism.”

On the flip side, Morocco has also furnished key intelligence with other nations. It was one of the countries to warn Germany about the Tunisian jihadi who was behind the attack last year at a Christmas market in Berlin.

On the homefront, ever since the Islamic State terror group expanded into North Africa, Morocco has faced a growing threat and the terror group has reportedly been targeting Morocco, planting sleeper cells from young people unknown to intelligence services.

Adelhak Khiame, the director of the BCJI, said that ISIS has even tried to “brainwash young girls on the internet to recruit them for an attack here.” The BCJI claims to have recently broken up a terror cell made up mainly of minor-aged girls.

Morocco has also sought to combat Muslim extremism by educating its own imams in a school of “moderate Islam,” where students are taught to accept different opinions and values.

“People have different religions and cultures. Therefore, we need dialogue and acceptance from all sides,” said the director of the school, Abdessalam Lazaar.

This softer version of Islam has also meant greater openness to the contributions of other faiths in building up Moroccan society.

The Moroccan government funded the restoration of the historic Ettedgui Synagogue in Casablanca to the tune of $844,000 last year as part of an effort to restore the city’s Old Medina. In December, Morocco’s King Mohammed VI attended the inauguration of the Synagogue and the adjacent El Mellah Jewish Museum.

The restoration of the synagogue and the museum included exhibits with paintings retracing the history of Judaism in Morocco in an effort to “preserve the authentic Moroccan identity,” according to Serge Berugo, head of the Council of Moroccan Jewish Communities.

Morocco is no stranger to the evils of Islamic terrorism. In 2003, the country suffered a series of suicide bombings in Casablanca, killing 45, and in 2011 terrorists set off a bomb in a Marrakesh café, killing 17 and wounding another 25.

Follow Thomas D. Williams on Twitter