They also expanded the Al-Qarawiyyin Mosque, which functioned as a religious centre and also educational institution.[1] When the Almohad leader Abd al-Mu'min besieged and conquered the city in 1145, he demolished the city's fortifications as punishment for its resistance.[3][2][12] However, due to Fes's continuing economic and military importance, the Almohad caliph Ya'qub al-Mansur ordered the reconstruction of the ramparts.[13]:36[12]:606 The walls were completed by his successor Muhammad al-Nasir in 1204,[13] giving them their definitive shape and establishing the perimeter of Fes el-Bali to this day.[3][12][4]