state loop works