Added logic to count items left in queue and to account for them in RI query limit.