Fix bug in determining last page.