@schiesbn will replace these with for loops.

We tried to understand what the whole logic was doing but didn't find a simple fix to move these blocks around without risking to break anything.

So for now using a `for` loop should do.