Fix the error but assume all elements have the same size; how to iterate over all the elements?