nested while loop works