Thanks a lot markdaoust!
Thanks to your comment we managed to streamline our code a lot in this vectorized way.
I’m sorry for the late reply, but still wanted to let you know that your comment helped us out quite a lot.
Kind regards
Odiel