Correctly calculate the number of pages