fixed infinite loop in batch mode