fix the logic of displaying pages
fix bugs and correct the logic