Rename document to livingdoc to avoid confusion

document is also a global variable, so it is less confusing to have the document variable called "livingdoc" or something else.