WIP: db and document writing.