Updated code so that paging works correctly for small items