Wadih's allies killed him, and the Cordoba garrison surrendered with the expectation of amnesty. However, "a massacre ensued in which the Berbers took revenge for many personal and collective injuries and permanently settled several feuds in the process". The Berbers made Sulayman caliph once again. Ibn Idhari said that the installation of Sulayman in 1013 was the moment when "the rule of the Berbers began in Cordoba and that of the Umayyads ended, after it had existed for two hundred and sixty eight years and forty-three days". In al-Andalus in the Taifa period During the Taifa era, the petty kings came from a variety of ethnic groups; some—for instance the Zirid kings of Granada—were of Berber origin. The Taifa period ended when a Berber dynasty—the Moroccan Almoravids—took over al-Andalus; they were succeeded by the Almohad dynasty of Morocco, during which time al-Andalus flourished. After the fall of Cordoba in 1013, the Saqaliba fled from the city to secure their own fiefdoms. One group of Saqaliba seized Orihuela from its Berber garrison and took control of the entire region. Among the Berbers who were brought to al-Andalus by al-Mansur were the Zirid family of Sanhaja Berbers. After the fall of Cordoba, the Zirids took over Granada in 1013, forming the Zirid kingdom of Granada. The Saqaliba Khayran, with his own Umayyad figurehead Abd ar-Rahman IV al-Murtada, attempted to seize Granada from the Zirids in 1018, but failed. Khayran then executed Abd ar-Rahman IV. Khayran's son, Zuhayr, also made war on the Zirid kingdom of Granada, but was killed in 1038. In Cordoba, conflicts continued between the Berber rulers and those of the citizenry who saw themselves as Arab. After being installed as caliph with Berber support, Sulayman was pressured into distributing southern provinces to his Berber allies. The Sanhaja departed from Cordoba at this time. The Zenata Berber Hammudids received the important districts of Ceuta and Algeciras. The Hammudids claimed a family relation to the Idrisids, and thus traced their ancestry to the caliph Ali. In 1016 they rebelled in Ceuta, claiming to be supporting the restoration of Hisham II. They took control of Málaga, then marched on Cordoba, taking it and executing Sulayman and his family. Ali ibn Hammud al-Nasir declared himself caliph, a position he held for two years. For some years, Hammudids and Umayyads fought one another and the caliphate passed between them several times. Hammudids also fought