rewrote pagination script