Fix remove and flush of single documents

Includes test from #755. Fixes #567.