nested loop works