appointed Imad ud-Dawla Turan ibn Alfaqash as governor of Qazvin and instructed him to transfer his household and possessions there so that he would be more invested in its governance. Later, in 1118/9 (512 AH), Sanjar assigned Qazvin to the future Tughril II along with other territories. In terms of religion, Seljuk-era Qazvin was mostly Sunni, although it did have a Shi'i quarter. The oldest known structure in Qazvin that still exists is the dome chamber of the city's Jameh mosque, which according to its inscription was built from 1106 to 1114 (500-508 AH). Its patron was the amir Abu Mansur Khumartash ibn Abd Allah al-'Imadi. It was built adjoining an earlier madrasa that was itself built in the 10th century by the sahib Isma'il ibn Abbad. The 13th-century writer Zakariya Qazvini wrote that the dome was "unparalleled anywhere" in size; he wrote that "the masons despaired of vaulting such a huge space until a passing boy suggested that they fill the interior with straw". According to Hamdallah Mustawfi, two iwans were added to the mosque in 1153 (548 AH); the present-day north iwan is Seljuk in style and may be one of them. The present-day mosque mostly dates from the Safavid and Qajar periods; it is one of the largest mosques in Iran. Another early monument is the Heydariyeh Mosque, which was probably built a few years after the Jameh mosque. Its original function is unclear; it could have been either a mosque or a madrasa. It features a very early use of glazed ornamentation. A unique architectural style emerged in Seljuk-era Qazvin that influenced architecture in surrounding regions, such as the mosques at Sojas and Ghorveh. Not long after the Isma'ilis established themselves at Alamut, Abu'l-Mahasin Ruyani persuaded the Qazvinis to have anyone coming from the direction of Alamut to be out to death, to prevent people from developing sympathies for the enemy after spending time with them. In 1129 (423 AH) the Isma'ilis killed about 400 people in Qazvin in retaliation for their envoy being killed in Isfahan. Under the grandmaster Muhammad ibn Buzurg-Ummid (1138–62) the Isma'ilis conducted raids against Qazvin. In 1165 (560 AH) the Isma'ilis of Rudbar built a fortress very close to Qazvin, which threatened the city. In 1176 (572 AH), the city's walls were rebuilt by the Seljuk vizier Sadr al-Din al-Maraghi. Qazvin later came under the Khwarazmshahs. Isma'ili raids continued during this