Better error handling in batch process