Added _dirty bool to Document, added tests