Moved Document to separate file, fix some errors