Make number of pages method more defensive