updated to iterate over the pixel array