Fix checks for existing mapping and document count