I would do these 2 last commands outside of the setTimeout. Is there a reason you're not doing this just after `showChunkOfMessages` ?

In any case I'd do it before the call to `getMessages`