Kenya's security response to the Islamist assault on the Dusit hotel complex in Nairobi shows the numerous lessons learned since a chaotic intervention when the Westgate mall was attacked in 2013, according to analysts.
The swift reaction, under a single chain of command, with the site rapidly cordoned off and procedures put in place to deal with survivors, has received widespread praise in the aftermath of the assault which left 21 dead, 28 injured and saw some 700 people rescued.
"It was an operation which appeared well-executed," said a regional security analyst, requesting anonymity.
"From a purely operational point of view, if the toll remains as it is, it is almost a miracle. We know how complicated it is, even with exceptionally well-trained people," he added, highlighting the tricky layout of the Dusit complex with its numerous buildings and parking lots.
"Across the spectrum, we've seen greater seriousness in all aspects of counterterrorism, both prevention and response," since Westgate, said Matt Bryden, director of the Sahan think-tank in Nairobi.
AFP journalists covered both attacks from the inside and while the first hours of the operation against Somali Islamist group Al-Shabaab in Westgate were marked by total confusion, the deployment of police forces and sealing off of the DusitD2 complex were done in an ordered and rapid manner.
In both cases, it was plainclothes police officers and armed civilians -- mostly from the Indian community -- who were the first to intervene and help rescue those caught inside.
At DusitD2 a number of heavily armed westerners, from private security companies and members of diplomatic security, were also present from the start.
More efficient, better tactics
Very quickly, elite Kenyan police units took over, while officers attached to the presidency also rapidly showed up.
Black-clad members of the anti-terrorist unit and members of the paramilitary General Service Unit (GSU) with their red berets quickly deployed as did a bomb squad.
"It was much more efficient, and it seems to have been better co-ordinated and the tactics they employed were better practised, they had better equipment so all in all, a much better performance," said Bryden.
The perimeter was quickly cordoned off and secured, in contrast to Westgate where it took until nightfall to seal off the area after the attack which began at lunchtime.
An AFP journalist at the scene in 2013 recalls onlookers asking police officers who lingered outside the mall as gunshots rang out inside, to give them their weapons so that they could go in and save lives.
Those who managed to flee the mall disappeared without a trace. At the Dusit those rescued were registered to be able to track their relatives while also ensuring the attackers were not taking advantage of the evacuations to escape.
Kenyan security forces managed to neutralise and kill all four gunmen in the Dusit -- while a suicide bomber blew himself up earlier -- by Wednesday morning after an operation of almost 20 hours.
At Westgate it took four days for the attack to be declared over, during which time a police officer was shot dead by a member of the army (KDF) in a friendly fire incident, power struggles raged, and soldiers were found to have looted stores in the mall. The attack left 67 dead.
On Tuesday and Wednesday at the Dusit, all deployed units reported to the GSU.
In the five years separating the attacks, Kenya's security forces were reorganised, elite units were better trained with the help of foreign partners, and a focus was placed on sharing of intelligence.
"Before, there was KDF intelligence, the NIS (National Intelligence Service) and at least one other police unit. So there were at least three agencies gathering intelligence but who were not communicating between themselves," said the security analyst.
Since Westgate, there has been a reorganisation of the National Counter Terrorism Centre, which has been relocated to the office of the president to put it in a more central and influential position, explained Bryden
These efforts have allowed Kenyan security services to foil several attacks in recent years.
"Since we know that they have been trying and trying and trying, I think it was inevitable that at some point, they would find a gap," said Bryden.