It's not possible to remove the test from the loop as count is modified within the loop, if count is 2320, it will iterate 3 times, 2 * BATCH_SIZE (=1000) + 320. So, I will prefer to leave it like that.