What did Avicenna write while he was imprisoned?