Cleanup and process_document correction