fix BeginDocument/EndDocument insertion
note changes