Added optional username field. Added better error handling in DocumentSaver.