Fix race condition in batch