You can simplify this logic a bit here, since you're guaranteed to always have exactly one batch.