Where was Avicenna twice imprisoned