PageManager: Refactor the code to make it cleaner.