modified pagination,some cleanup