Unnest loops

Reusing the same iterator variable in a nested loop is a bug. In this case it is better to not have nested loops at all, because we only have to create one array.