The madrasa was an institution which originated in northeastern Iran by the early 11th century and was progressively adopted further west. These establishments provided higher education and served to train Islamic scholars, particularly in Islamic law and jurisprudence ("fiqh"). The madrasa in the Sunni world was generally antithetical to more "heterodox" religious doctrines, including the doctrine espoused by the Almohad dynasty. As such, it only came to flourish in Morocco in the late 13th century, under the Marinid dynasty which succeeded the Almohads. To the Marinids, madrasas also played a part in bolstering the political legitimacy of their dynasty. They used this patronage to encourage the loyalty of the country's influential but independent religious elites and also to portray themselves to the general population as protectors and promoters of orthodox Sunni Islam. Finally, madrasas also played an important role in training the scholars and elites who operated the state bureaucracy.