Safer implementation of Swap()

Also added documentation, unit tests for swapping Document/Value,
Document/Document.