Added robustness to the document revision. Added test coverage.