Cappadocia. In 392 A.D., emperor Theodosius I divided Armenia Minor into two new provinces: First Armenia, with its capital at Sebasteia (modern Sivas); and Second Armenia, with its capital at Melitene. Middle Ages and Ottoman rule During the reign of the Emperor Justinian I (527–565), administrative reforms were carried out in this region: The province of Second Armenia was renamed Third Armenia (Armenia Tertia), with its territory unchanged and its capital still at Melitene. Melitene's city walls were constructed in the 6th century by the emperors Anastasius and Justinian. Those that still stand mostly date from the Arab period, perhaps of the 8th century, though retaining the layout of and some remnants from earlier building phases. The city was captured by the Rashidun Caliphate in 638. It then became a base for their raids deeper into the Byzantine Empire, a policy continued by the Abbasids. In the 9th century, under its semi-independent emir Umar al-Aqta, Malatya rose to become a major opponent of the Byzantine Empire until Umar was defeated and killed at the Battle of Lalakaon in 863. The Byzantines attacked the city many times, but did not finally take it until the campaigns of John Kourkouas in 927–934. After successively accepting and renouncing vassal status, the city was finally taken in May 934, its Muslim inhabitants driven out or forced to convert, and replaced by Greek and Armenian settlers. The West Syrian diocese of Melitene has been established since the sixth century and was as well surrounded by other bishoprics belonging to nearby towns. In the tenth century the Emperor Nikephoros II Phokas convinced the Jacobite Patriarch of Antioch to move the head of the patriarchate into the region of Melitene. The city was attacked and devastated by the Seljuks in 1058. In the period that followed the Turkish advance into the Byzantine Empire after the defeat at the Battle of Manzikert, Gabriel of Melitene, a Greek Orthodox Armenian who had risen from the ranks of the Byzantine army, governed the city. From 1086 to 1100 he preserved his independence with the aid of the Beylik of the Danishmends. After 1100, he invested heavily on the commanders of the First Crusade, especially Bohemond I of Antioch and Baldwin of Boulogne. The Danishmends took over Malatya one year later in 1101 (see Battle of Melitene). With the Anatolian Seljuk Sultanate based in Konya taking over the Beylik of Danishmend