Since you need to count anyway, don't use the iterator here, just access thumbnails[i].