fix critical error on document destroy