Fix bug with page number calculation