to examine one's reputation against a prominent local resident. The person whom Avicenna debated against was Abu'l-Qasim al-Kirmani, a member of the school of philosophers of Baghdad. The debate became heated, resulting in Avicenna accusing Abu'l-Qasim of lack of basic knowledge in logic, while Abu'l-Qasim accused Avicenna of impoliteness. After the debate, Avicenna sent a letter to the Baghdad Peripatetics, asking if Abu'l-Qasim's claim that he shared the same opinion as them was true. Abu'l-Qasim later retaliated by writing a letter to an unknown person, in which he made accusations so serious, that Avicenna wrote to a deputy of Majd al-Dawla, named Abu Sa'd, to investigate the matter. The accusation made towards Avicenna may have been the same as he had received earlier, in which he was accused by the people of Hamadan of copying the stylistic structures of the Quran in his Sermons on Divine Unity. The seriousness of this charge, in the words of the historian Peter Adamson, "cannot be underestimated in the larger Muslim culture." Not long afterwards, Avicenna shifted his allegiance to the rising Buyid amir Shams al-Dawla (the younger brother of Majd al-Dawla), which Adamson suggests was due to Abu'l-Qasim also working under Sayyida Shirin. Avicenna had been called upon by Shams al-Dawla to treat him, but after the latters campaign in the same year against his former ally, the Annazid ruler Abu Shawk (), he forced Avicenna to become his vizier. Although Avicenna would sometimes clash with Shams al-Dawla's troops, he remained vizier until the latter died of colic in 1021. Avicenna was asked by Shams al-Dawla's son and successor Sama' al-Dawla () to stay as vizier, but instead went into hiding with his patron Abu Ghalib al-Attar, to wait for better opportunities to emerge. It was during this period that Avicenna was secretly in contact with Ala al-Dawla Muhammad (), the Kakuyid ruler of Isfahan and uncle of Sayyida Shirin. It was during his stay at Attar's home that Avicenna completed his Book of Healing, writing 50 pages a day. The Buyid court in Hamadan, particularly the Kurdish vizier Taj al-Mulk, suspected Avicenna of correspondence with Ala al-Dawla, and as result had the house of Attar ransacked and Avicenna imprisoned in the fortress of Fardajan, outside Hamadan. Juzjani blames one of Avicenna's informers for his capture. Avicenna was imprisoned for four months, until Ala al-Dawla captured Hamadan, thus putting an end to Sama