Refactoring of onEnterPage and some related methods