fix script hanging after the first batch