Allow document's metadata to be stored in _meta

DocType's metadata has been moved to _doc_type
Metadata fields are automatically stored in _meta
Minor cleanup and some comments