Refactoring page code