Fix batch mode handling exceptions. Refactor batch tests.