updated the count code dealing with pagination