Abdulhamid Daar's dreams of joining al-Shabaab began as a teenager in Toronto, with long sermons from imams on how Islam was under grave threat, making it the duty of believers to fight and defend the faith. This took the 23-year-old engineering student on a journey to Somalia and jihad.
He experienced the excitement and satisfaction of being involved in the struggle for what he believed to be a righteous cause. But he also saw friends being killed, and felt the constant fear that he, too, would die or be left crippled.
He resisted constant entreaties from his mother and four brothers and sisters to return home. He left in the end, he says, because al-Shabaab became deeply divided and turned on itself viciously. Foreign volunteers began to be executed on the orders of the movement's 36-year-old leader, Ahmed Abdi Godane, also known as Mukhtar Abu Zubeyr.
"He began seeing enemies everywhere, people kept getting accused of being spies and that meant no one was safe," said Abdulhamid Daar. "A lot of people have left, a lot have died, but the Shabaab can still keep going. You saw what happened in Nairobi – there will be others in different countries. That is what Abu Zubeyr wants, that's his mission and we used to say he will continue with it until a drone gets him."
Abdulhamid Daar (not his full name) is one of a growing number of volunteers from abroad who have left the ranks of Somalia's Islamist movement as it goes through this period of internal bloodletting. Since leaving East Africa three months ago he has been in Amsterdam and Rome; he will not go to Britain or the US, in case he ends up "somewhere like Guantanamo". He refuses to say what kind of travel documents he has been using, and indignantly rejects suggestions that he and others like him have been in contact with Western security services.
The desertions and rifts within the organisation come, say analysts, when it should have been consolidating, stepping up recruitment and reaching out to the myriad clans in Somalia, as it prepared for a campaign abroad while facing African Union troops and US air strikes at home.
The attack on the Westgate shopping centre cost 70 lives and gave enormous publicity to al-Shabaab, with its adherence to al-Qa'ida. On top of this, there were reports about Samantha Lewthwaite, the "White Widow" of one of the London 7/7 bombers who was possibly involved. More kudos in the world of Islamist extremism followed when its fighters drove off US forces targeting one of its leaders suspected of organising the Nairobi assault.
Al-Shaabab's use of social media was also widely noticed. It is, in fact, something that al-Shabaab began in 2007, but Westgate showed just how slick it had become in the intervening years. The movement was able to get its version of the unfolding drama across, its spokesmen, often speaking English, keeping journalists updated.
But being active in high-profile international jihad inevitably brought renewed attention from the West. The attempt by the US Navy Seals to capture Abdulkadir Mohamed Abdulkadir, known as Ikrima, may have failed, but a week later, one of the movement's bombmakers, Ibrahim Ali Abdi, who had been particularly proficient at preparing suicide attackers, was killed in a drone strike at Jilib, south of Mogadishu.
"Al-Shabaab could take some satisfaction," said Bruce Hoffman, director of the Centre for Security Studies at Georgetown University in Washington. "After all, they repulsed the world's most powerful military force. On the other hand, they get a pretty disquieting message that the US is willing to intervene and bring the war right to their doorstep."
The US State Department has warned that other attacks may be initiated by the Somali Islamists in the region, with Uganda a possible target; the country has already suffered from Somali terrorism – around 80 people were killed in a suicide bombing in Kampala in 2010.
Apprehension about al-Shabaab has led to Western pledges to reinforce the African Union Mission in Somalia (Amisom) force, and several countries, including Britain, are looking at expanding the training programme for Somali government forces; the American military is drawing up new contingency plans for combating extremist violence in the Sahel and north Africa.
Western intelligence agencies say they have noticed increasing links between al-Shabaab and other Islamist groups such as al-Qa'ida in the Islamic Maghreb (AQIM) and Boko Haram. It is not clear just how strong these connections are, but there is evidence that they will act in support of each other. France's intervention in Mali was preceded by an attempt to rescue a hostage being held in Somalia. In the event, the attempt failed, and Dennis Alix, an officer with DGSE, the French security service, was executed.
"Is al-Shabaab ready to face the sanctions from the world's most advanced military machines because of the role it wants to play in global jihad?" asked Robert Emerson, a British security analyst. He pointed to the purges which have been taking place. "Abu Zubeyr is trying exert total control over the organisation, so the future will depend on his judgement, and who's left to take over if he dies."
The International Institute of Strategic Studies in London has charted how "the power struggles within al-Shabaab have transformed the leadership. One by one, prominent leaders have been killed, arrested or forced to flee."
The losers have included Sheikh Hassan Dahir Aweys, formerly seen as the group's mentor, who tried to escape the hardliners and is now under Somali government arrest; the co-founder Ibrahim al-Afghani, who, as his name suggests, trained in Afghanistan and was an associate of Osama bin Laden, was killed earlier this year; Mukhtar Robow, a spokesman, has fled back to his Rahanweyn clan.
It has been reported that also among the casualties were two prominent foreign fighters, Omar Hammami, a US citizen and Habib Ghani, or Osama al-Britani, a Briton of Pakistani origin, who were hunted down and shot dead two months ago.
Hammami, from Alabama, was one of the first to urge al-Shabaab to embrace social media. The "rapping jihadist" as he became known, had a $5m (£3m) FBI bounty on his head. In one of his last tweets he said: "Abu Zubeyr has gone mad, he is starting a civil war." Al-Britani, from Hounslow, west London, was close to Samantha Lewthwaite; according to some reports, they had married. The pair went on the run in Kenya at the same time after becoming suspects in a bomb plot.
Abu Zubeyr has no doubt that his vision of universal ummah (Islamic community) will be achieved through jihad. He had requested a merger with al-Qa'ida but Bin Laden was critical of some of al-Shabaab's tactics, warning in a letter that enemies would "escalate their anger and mobilise against you; this is what happened to the brothers in Iraq and Algeria".
Documents discovered at Bin Laden's home in Abbottabad, in Pakistan, showed that his deputy, Ayman al-Zawahiri, took a different view. He had written: "Please reconsider your opinion not to declare the accession of the brothers of Somalia." In February last year, Abu Zubeyr sent a message to al-Zawahiri, who had succeeded Bin Laden, saying: "We will go with you as loyal soldiers until doom and injustice disappears from Islam."
Following the Nairobi attack Abu Zubeyr issued an audio statement declaring: "Just 10 days after the anniversary of the blessed 9/11 operations an epic battle has been launched." Kenya would face "a war of attrition inside your own country" for sending troops to support Amisom; and Uganda, which has also joined the force, will face bloody retribution: "What happened in Kampala is just the beginning."
It remains to be seen whether al-Shabaab has the means to spread such havoc. It is estimated to have between 10,000 to 12,000 men under arms and as the Nairobi attack showed, active sympathisers outside Somalia.
Although Abu Zubeyr has lost some senior commanders, many of them liquidated on his orders, he retains the support of Mahad Mohamed Ali ("Karate") who runs Amniyat, the organisation's secret police.
Loss of territories has meant a shrinkage of money gained from taxes on shipping and charcoal; but it has found alternative revenue streams of up to $100m a year, according to the United Nations, from links to piracy, drugs and ivory smuggling.
And, despite deaths and defections, the supply of foreign recruits have not dried up. Al-Shabaab recently released a video of British Muslims who had become "martyrs" fighting in Somalia. They included "Talha", whose real name is Taufil Ahmed, of Bangladeshi heritage. Holding a rifle he declares: "All the Muslims in Britain, especially the people of Tower Hamlets, the citadel where I was born – I call upon you to come to the jihad."
Two years ago, Sir Jonathan Evans, then director general of MI5, stated that Somalia had become second only to Pakistan as a destination for British Muslims seeking jihad. Both have now been supplanted by Syria; but there are still those who want to join al-Shabaab.
Abdulhamid Daar, exiled from Canada and Somalia, claimed there was still recruitment going on in North America. "I think the numbers had gone down, but they may be rising again after all the publicity over Nairobi; it's mainly in the Toronto area and also Minnesota, where there are a lot of Somalis.
"Some of us now believe one can take part in jihad without killing people or getting killed. It is really about promoting pure Islam by the way you live," he added. "But I don't think these young guys would listen to what we say: they would have to find out for themselves."