fix old bugs and cleanup

• check missing DocumentCategory object
• set document_category_id null if 0