final tweaks on per-page algorithm