fix to handle large number of pages gracefully