count the pages and runs more safely