Improve batch handling

Related to #834