Propagate fix for issue #31 and ensure that batch process closes the resources only at the end of the batch