Upon his return to Cairo, he was given an administrative post. After he proved unable to fulfill this task as well, he contracted the ire of the caliph al-Hakim, and is said to have been forced into hiding until the caliph's death in 1021, after which his confiscated possessions were returned to him. Legend has it that Alhazen feigned madness and was kept under house arrest during this period. During this time, he wrote his influential Book of Optics. Alhazen continued to live in Cairo, in the neighborhood of the famous University of al-Azhar, and lived from the proceeds of his literary production until his death in c. 1040. (A copy of Apollonius ' Conics, written in Ibn al-Haytham's own handwriting exists in Aya Sofya : (MS Aya Sofya 2762, 307 fob., dated Safar 415 A.H. [1024]).)