Bug #1301 & #1292

Check all documents before exiting opencs.

Please review, all comments welcome.