Added Pagination algorithm