refactored Paginize, the refactor fixed a series of bugs.