fix calculation of num pages