refactor code logic of current and all pages in pages_select file