refactor page current and selected function