Fix document validation and orphaned data