Last years of Ibn Sina (Avicenna) were spent in the service of the Kakuyid ruler Muhammad ibn Rustam Dushmanziyar, also known by his surname Ala al-Dawla Muhammad. Muhammad was not defeated by Seljuq forces, but began constructing instead massive defensive walls around Isfahan which later saved it from these Turkmen nomads who sacked and plundered some places in west and central Iran in 1038/39, including the city of Hamadan.