improved flattening of subpatterns with numeric indices

Now it works for every combination or arrays and objects.