Fixing destruction of the document