refactoring show page function