refactored code when adding/deleting docs from batch