Factor mean-of-batches into a helper function.