updated replacepage method