Wouldn't we miss the last chunk if it's smaller than batch size?

I think if you take another look at the previous loop, you will find that it does it's job and it's simpler.