changed how totalPages is calculated