corrected page index algorithm