Moved code to checkPagination