loop on index working perfectly