An Arab incursion into western Georgia led by Marwan II, was repelled by Leon I (r. 720–740) jointly with his Lazic and Iberian allies in 736. Leon I then married Mirian's daughter, and a successor, Leon II exploited this dynastic union to acquire Lazica in the 770s. The successful defence against the Arabs, and new territorial gains, gave the Abkhazian princes enough power to claim more autonomy from the Byzantine Empire. Towards 778, Leon II (r. 780–828) won his full independence with the help of the Khazars and was crowned as the king of Abkhazia. After obtaining independence for the state, the matter of church independence became the main problem. In the early 9th century the Abkhazian Church broke away from Constantinople and recognized the authority of the Catholicate of Mtskheta; the Georgian language replaced Greek as the language of literacy and culture. The most prosperous period of the Abkhazian kingdom was between 850 and 950. A bitter civil war and feudal revolts which began under Demetrius III (r. 967–975) led the kingdom into complete anarchy under the unfortunate king Theodosius III the Blind (r. 975–978). A period of unrest ensued, which ended as Abkhazia and eastern Georgian states were unified under a single Georgian monarchy, ruled by King Bagrat III of Georgia (r. 975–1014), due largely to the diplomacy and conquests of his energetic foster-father David III of Tao (r. 966–1001). 