refactoring page display logic