Programming mantra of the day - repeat after me:
Do not erase items from an array that you are currently iterating over.
First iterate, then erase.
I know this by heart but it seems I need a couple of decades more time to not fall for it once in a while 🤣