document, make internals private, remove unsafe Document.apply function