Safer implementation of Swap()

Also added documentation, unit tests for swapping Document/Value,
Document/Document.
Merge pull request #48 from miloyip/Swap

Safer implementation of Swap()