Even as the Islamic State group's rule is being torn down in Iraq, the seeds are there for it — or a successor extremist group — to rise again one day.
It's a disquieting fact: There are those among Iraq's Sunni Muslim minority who find some good in the group, though they denounce the militants for suffering inflicted during their nearly three-year rule.
Listen to the words of a young Iraqi who was impressed by an Islamic State cleric — a compassionate man, Mowafy Abdul-Qader said, recalling his "sweet demeanor" as he gave lessons on Shariah law.
"He taught me like he was an angel from heaven. He was accurate and righteous," Abdul-Qader said, speaking at a camp for Iraqis driven from their homes during the past year's fighting to uproot the militants in northern Iraq. "Because of people like him, I sometimes felt I was actually living in a real caliphate."
In nearly two dozen interviews with Sunnis living in the camps of the displaced, The Associated Press heard many variations on the same theme: IS was too brutal and individual members were corrupt, but its goals to restore morality and faith were worthy.
The direction of Sunni sentiment can have great significance for Iraq's future. There are fears militants could take root again if Sunnis' lives are not rebuilt or if the Shiites who dominate the government don't end past discrimination and give Sunnis a share of political power.
When the Sunni militants overran much of Iraq and Syria in 2014, the group's dream of an ideal Islamic rule had appeal among some in the community. Iraq's Sunnis in general are deeply conservative and feel oppressed under the majority Shiites. So some saw hope in a group promising to bring morality, uplift Sunni Islam and implement God's law, which many felt would ensure justice.
Instead, the self-declared caliphate turned into a bloody horror. The group committed atrocities on a startling scale, including a systematic network of sex slavery and rape against the Yezidi religious minority and mass killings that targeted everyone, including Sunnis. Prisoners were shot or beheaded, or even set on fire, drowned or blown up with explosives.
Religious police were relentless in punishing the slightest transgressions. Punishments included stoning, beheadings, amputations and whippings. Suspected spies — including those simply caught with a mobile phone— and policemen or soldiers were among those dragged into public squares for death. IS members took the lion's share of resources, alienating others struggling to get by.
After the extremists' brutality, some now say they reject anyone promising to bring "true Islam."
"We cannot trust them anymore. We don't want Islamists to rule us," said Mohammed Ibrahim, a government employee in Mosul.
In one camp for the displaced, the imam delivering the Friday sermon urged worshippers not to shun their religion on account of horrors they experienced under IS. "Return to your true faith," he said, according to several men who heard the sermon.
Khaled Shaaban, a displaced Mosul resident, said he used to pray five times a day, but ever since IS took over he hasn't set foot in a mosque. "It was like military rule, only religious. Like a checklist: beard, check. Short pants, check. No smoking, check."
Another of the displaced said the militants' sermons never addressed the concerns of the people. Instead, "they admonished us for 'crying' over the scarcity of basic food items like bread and rice," and told people to endure deprivations, Abed Ahmed said.
Ali Abu Graer, a member of the Shamar, a large tribe in Iraq and the Gulf region, said IS members sounded like they knew religion well, "but when you see their actions you wonder who they really are. What do you make of a people who set a fellow human being on fire in front of your very eyes? What do you make of a people who kill you because they found that you are in possession of a mobile phone?"
Others seemed more conflicted.
Sitting outside the tent he shares with his pregnant wife, Mowafy Abdul-Qader recounted how a passing IS patrol saw that his wife and sister were not meeting the militants' dress code as they worked with him at their farm. As their guardian, he was ordered by the militants to take Shariah lessons from an IS cleric, an Egyptian.
He struggled to reconcile the kindly and pious cleric with everything else he saw from the group.
"Shedding blood was easy for Daesh. It was easy for them to kill Muslims," he said, using the Arabic acronym for IS. Also, he said, the group shut down most university colleges in Mosul. It's a sore point because he himself was studying to qualify to teach Islam in school. "They speak of the glory of Islam, but they destroyed the education system needed to build the nation of Islam."
But then he, like almost all the others interviewed, said he supported in principle the group's imposition of dress codes for women in public, saying it boosted public morality. Before the militants came, women in Mosul sometimes dressed unacceptably, including wearing pants, Abdul-Qader lamented.
School headmaster Mohammed Jassim said IS revived interest in religion, getting people to learn more about prayer, fasting and charity. "Young men filled the mosques after years of religious decline," he said.
But "the actions of many of them ran contrary to what they preached," he said.
"They taught people a great deal about our religion," said another camp resident, Abed Hamad. He said people began to read and debate Hadeeth, the stories and sayings of the prophet Muhammad that alongside the Quran are used as a basis of Islamic law.
Several praised the group's poets and singers of religious anthems called "anasheed" in Arabic. The songs were played at kiosks known as "media centers" in IS-held areas, accompanied by videos of fighting and militants killing captives or suspected spies.
IS "anasheed" extolled the virtues of jihad, ridiculed enemies and eulogized fallen fighters, all in the elevated poetic language of traditional religious hymns.
Those songs are among the traces IS left behind, and new followers might one day rally round them, much as neo-Nazis embrace Nazi regalia and white nationalists fly Confederate flags.
In one camp for the displaced, a 9-year-old boy could sing an anthem off the top of his head. It was a light-hearted children's tune, but with bloody lyrics listing cities the militants captured: "The soldiers of the caliphate are brave, the army of the heretics ran away, and now we have Fallujah, Mosul and Tikrit."
As the militants have been driven out, the Iraqi government has introduced standardized Friday sermons for imams to deliver in the mosques of Mosul and Anbar province, the mainly Sunni region of western Iraq. The policy aims to ensure no militant ideas or hate speech toward minorities are disseminated.
That is the approach governments across the region have taken, denouncing IS as criminals masquerading as defenders of Islam. Mainstream Muslim clerics say IS cherry-picked what it wanted from Islamic texts and history and then misinterpreted those parts to support its rabidly violent practices, while ignoring everything in the faith that contradicted them.
"The so-called caliphate will disappear sooner or later, and what it will leave as its legacy will be a bitter taste for Muslims and non-Muslims alike," said Ibrahim Negm, an adviser to Egypt's grand mufti and the head of a state-backed center tasked with debunking militant ideology online.
But such sweeping denunciations — by clerics whom opponents often dismiss as tools of government — can underestimate the methods militants use to gain support.
"The culture left behind by IS will be preserved for a long time," said Thomas Hegghammer, director of terrorism research at the Norwegian Defense Research Establishment in Oslo. He noted that Islamist poetry from the 1960s and anasheed from Afghanistan in the 1980s are still used among jihadi supporters.
He warned that eventually "nostalgia" over the Islamic State group could arise.
"People will say we had a caliphate, but our enemies destroyed it," he said. "Muslims who were too young at its heyday and could not join it will romanticize it ... It will for a long time be like the notion of a 'lost caliphate.'"