Issue #239: Fix race condition in batch processing logic