Minor bug fix, when writing into the same document