Changed the logic for adding new pages