Fix bug re batch search returning more records than limit

 - When searching in batches, could return more than the requested
   limit; need to revise the limit with the last batch
 - Code to do so is ugly but sufficient
 - Revised test-batches.R to cover this case