fixing iteration with indexes