Changed the way the loop works for Page generation