and country. Despite internal infighting, Abu Said Uthman II (r. 1310–1331) initiated huge construction projects across the land. Several madrasas were built, the Al-Attarine Madrasa being the most famous. The building of these madrasas were necessary to create a dependent bureaucratic class, in order to undermine the marabouts and Sharifian elements. The Marinids also strongly influenced the policy of the Emirate of Granada, from which they enlarged their army in 1275. In the 13th century, the Kingdom of Castile made several incursions into their territory. In 1260, Castilian forces raided Salé and, in 1267, initiated a full-scale invasion, but the Marinids repelled them. At the height of their power, during the rule of Abu al-Hasan Ali (r. 1331–1348), the Marinid army was large and disciplined. It consisted of 40,000 Zenata cavalry, while Arab nomads contributed to the cavalry and Andalusians were included as archers. The personal bodyguard of the sultan consisted of 7,000 men, and included Christian, Kurdish and Black African elements. Under Abu al-Hasan another attempt was made to reunite the Maghreb. In 1337 the Abdalwadid kingdom of Tlemcen was conquered, followed in 1347 by the defeat of the Hafsid empire in Ifriqiya, which made him master of a huge territory, which spanned from southern present-day Morocco to Tripoli. However, within the next year, a revolt of Arab tribes in southern Tunisia made them lose their eastern territories. The Marinids had already suffered a crushing defeat at the hands of a Portuguese-Castilian coalition in the Battle of Río Salado in 1340, and finally had to withdraw from Andalusia, only holding on to Algeciras until 1344. In 1348 Abu al-Hasan was deposed by his son Abu Inan Faris, who tried to reconquer Algeria and Tunisia. Despite several successes, he was strangled by his own vizir in 1358, after which the dynasty began to decline. Decline After the death of Abu Inan Faris in 1358, the real power lay with the viziers, while the Marinid sultans were paraded and forced to succeed each other in quick succession. The county was divided and political anarchy set in, with different viziers and foreign powers supporting different factions. In 1359 Hintata tribesmen from the High Atlas came down and occupied Marrakesh, capital of their Almohad ancestors, which they would govern independently until 1526. To the south of Marrakesh, Sufi mystics claimed autonomy, and in the 1370s Azemmour broke off under a coalition of merchants