refactor pagination