A year ago, Somalia's government and African Union troops were on the move against al-Shabab, taking over town after town. The al-Qaida-linked militants were in clear retreat, and violent in-fighting among top leaders was shaking the group.
Since then, the tables have turned and al-Shabab appears resurgent with renewed attacks inside and outside Somalia, most notably the assault on an upscale Kenyan shopping mall in September that killed more than 60 civilians.
Analysts say the Islamist militant group should never be underestimated.
In its seven-year existence, al-Shabab has faced strong opposition, including the Ethiopian intervention into Somalia, drone attacks that target top leaders, and the military forces of the Somali government and African Union mission, AMISOM.
But the group has persevered, and according to Cedric Barnes of the International Crisis Group, the setbacks of 2011 and 2012 may have increased its ability to attack.
"In a way what you see is AMISOM swapping roles with al-Shabab," he says. "Shabab for a time controlled an awful lot of territory in Somalia, but perhaps was more limited by the fact it had more administrative and day-to-day responsibility for a large number of people, especially in urban areas....
"And now AMISOM is in a similar position to al-Shabab before the big offensive -- its lines are more stretched, it has more responsibility to populations, logistics, whereas al-Shabab is more free from those responsibilities and now it has more capacity to react and change tactics quickly."
In-fighting leaves Godane in charge
In addition, al-Shabab appears to have settled internal unrest after the group's top leader, Ahmed Abdi Godane, carried out a purge of his opponents.
The wrangling first came to light in February 2011 when, according to sources within al-Shabab, several senior leaders accused Godane of straying from the group's core values and showing dictatorial tendencies.
The critics, who included Godane's top two deputies Ibrahim Afghan and Mukhtar Robow Ali Abu Mansour, said Godane violated Islamic laws by describing true Muslims as non-believers and executing Muslims without a trial. They also accused him him of strategic blunders such as fighting against the Ahlu Sunna militia in central Somalia and the Hiran region.
Godane responded to the challenge against him with combination of pragmatism and violence. First, in February 2012, he announced a merger with al-Qaida to boost his group's prestige in the militant world.
Then, in June this year, Godane reportedly ordered the killing of his opponents. Two of them -- number two deputy Ibrahim Afghan and Ma’alim Hashi, leader of the Shura consultative council, were executed on June 19 in Barawe town.
A third target, Hassan Dahir Aweys, escaped by a whisker. He is now in a Somali government jail after leaving Barawe on a boat. A fourth target, Godane's first deputy Mukhtar Robow, is on the run in the jungle in Bay and Bakool regions.
Godane is also allegedly behind the killing of some foreign militants who challenged his leadership, including the American-born Omar Hammami, who made English-language videos meant to appeal to Islamist militants in the U.S.
Earlier this year, Taufail Ahmed of Britain and Dr. Khalid Al-Kene of Kenya were killed execution style in Barawe. Both had disagreements with Godane before their death.
Those who know him describe Godane as a tough leader who studies people in the militant group, and classifies his opponents as those who are persuadable and those who pose a threat to his control.
Cedric Barnes says in a country like Somalia, you do not rise to a position like Godane's by being consultative and mild-mannered.
“He obviously has had for a long time a deep ambition to be the leading figure in al-Shabab as well as on the wider East Africa stage as well as appealing to the global jihad agenda represented by al-Qaida," Barnes says. "So of course he has to show a very tough side and brutal side to his leadership, which is not unusual (given) the kind of organization al-Shabab is, which is both a terrorist organizational as well as an insurgency."
Mohamed Farah Al-Ansari is a former al-Shabab commander who now works with the Somali government. He says that despite the internal wrangling and military setbacks of the past couple of years, al-Shabab remains well organized and continues to raise money through various means and sources, mostly from inside Somalia.
"They rely on charcoal, which is exported from Barawe town," he says. "They also collect extortion money from poor, ordinary people; they tell them to pay one-third of their wealth with livestock, forms of other wealth, and they cannot refuse. They apply the same extortion money to Hawala (money services), telecommunication companies."
Experts say al-Shabab also collects money through taxes. When someone is building a new home they are taxed $120. A sesame farmer must pay a tax of about $4 on each sack he sells. Goods that are being transported are levied taxes of about $4.50 per sack, paid at roadside checkpoints.
Meanwhile, Godane has the support of determined young militants known as Amniyat, who assist him with sophisticated intelligence, training and commando-style operations. These militants operate like federal agents, independent from regional administrations. The Amniyat are accountable to Godane only, and he regularly replaces their commander to prevent any challenges.
In one instance earlier this year, the Amniyat sent death threats to Zubayr Al-Muhaajir, another prominent militant from abroad. Al-Muhaajir, a theologian who was acting as the supreme judge in al-Shabab's tribunals, had denounced Godane at a mosque one Friday and accused him of deviating from Islamic principles.
Amniyat advised him to prepare his “karfan,” the white sheet used to cover dead bodies. He was arrested in June this year and is now believed to be in detention in Barawe town.
Godane and al-Shabab also have a powerful media operation that targets people both inside and outside Somalia. For the foreign audience, the group sends out messages on Twitter, YouTube and jihadist websites. Sometimes, it sends out cleverly crafted videos meant for broadcast by the international media.
Inside Somalia, al-Shabab media officers routinely visit regions to propagate the group's message through videos and pictures. Video clips of jihadist fighters from Afghanistan, Chechnya and Yemen are shown. Also shown are videos of the war in Somalia.
Al-Shabab's continuing capability was made clear by the recent assault on shoppers in the Westgate mall in Nairobi. Kenyan investigators say the operation was extensively planned, and that the gunmen had stashed weapons inside the mall ahead of the attack.
The ICG's Barnes says the attack was a reminder and a clear statement of al-Shabab's ability to act against high-profile targets.
"But," he says, "it was also a very clear message to the wider world, to the international community and perhaps also to al-Qaida that it was, or is the number one militant organization in east Africa and it should be taken seriously."
The U.N. Security Council recently authorized deployment of another 4,000 African troops to Somalia. It appears that despite hopes of peace, Somalia is not done fighting al-Shabab and there may be some heavy fighting to come.