(#656) - fix loosing deletion of document

See #656.

In some specific situation deletion of document could get lost. Fix and test attached.