index loop works