Fixed cleanup in batch mode