 Complete the following phrase:  After joining the caliphal court, al-Afshin quickly became one of the leading figures in the Abbasid military establishment. During the caliphate of al-Mamun, he was sent to Barqa and, in 831, to Egypt, in order to suppress rebel activity in those provinces. After al-Mutasim became caliph, he was given a major command as the leader of the war against Babak al-Khurrami in Adharbayjan, and after a two-year campaign 835837 he succeeded in destroying the rebellion and capturing its leader. Following this, he was put in charge of part of the Muslim army during al-Mutasims 838 expedition against the Byzantines, and he played a leading role during the 