refactor itemsPerPage code, fixes #133