while a loyalist army sent against them was thrown back after many of the Kutama in its ranks defected. In response, in April/May 912, al-Mahdi officially proclaimed his son, Abu'l-Qasim Muhammad, as heir-apparent (), gave him the regnal name ('He who executes God's command'), and placed him in nominal charge of the army sent to quell the revolt. On 21 June 912, the loyalist army decisively defeated the rebels near Mila. The anti- al-Mawati and the other rebel leaders were soon captured, and prominently featured in al-Qa'im's triumphal entry into Kairouan in autumn. Later reign Foundation of Mahdiya The anti-Kutama riots in Kairouan and al-Qasr al-Qadim highlighted the vulnerability of the palace city of Raqqada, which was poorly fortified. Already in 912, al-Mahdi began seeking a new, and more defensible, site for his residence.He personally travelled the coast for this purpose, even visiting the ruins of ancient Carthage, before settling on the small peninsula of Jumma. A rocky peninsula of about length and only wide at its base, it was eminently defensible from a land-based attack, and included an ancient Punic artificial harbour cut into the rock. Construction began on 11 May 916 with a massive landward wall, whose single gate was considered an engineering masterpiece: the trick of installing the doors on beds of glass, so that a single person could open them, was said to have come from al-Mahdi himself. The new palace city was fortified on the seaward side as well, and included a great congregational mosque—the only Fatimid-era structure to survive to modern times—two palaces, one for the caliph and one for his heir-apparent, and other buildings for the caliphal court and administration. The only weakness of Mahdia was its lack of natural resources, especially water; large grain stores and cisterns were built for rainwater, but in case of a siege, the city would have to be supplied by sea. As heavy rainfall damaged the palaces in Raqqada, al-Mahdi expedited the move into the new residence with his court, which took place on 20 February 921, although construction was still ongoing. Mahdiya was palace city, arsenal, treasury, and military stronghold in one; only the Fatimid family and its most loyal members were settled there. The garrison was provided by black African slave troops (), as well as by Slavic slave soldiers and Kutama. The Zawila and Kutama soldiers lived mostly in the city's suburb outside the