Fixes a bug on writing documents.