Finished most of the document logic.