bug fix: big page number can make code loop forever