Bug fix for multidimensional arrays/objects in loops