anchor.diff:          end
       end.
   
  -changes_enumerator(#doc_info{id= <<"_local/", _/binary>>, high_seq=Seq},
  -        {Db, _OldSeq, Args, Options}) ->
  -    {ok, {Db, Seq, Args, Options}};
  -changes_enumerator(DocInfo, {Db, _Seq, Args, Options}) ->
  -    #changes_args{
  -        include_docs = IncludeDocs,
  -        filter = Acc
  -    } = Args,
  +changes_enumerator(#doc_info{id= <<"_local/", _/binary>>, high_seq=Seq}, Acc) ->
  +    {ok, Acc#cacc{seq = Seq, pending = Acc#cacc.pending-1}};
  +changes_enumerator(DocInfo, Acc) ->
  +    #cacc{
  +        db = Db,
  +        args = #changes_args{include_docs = IncludeDocs, filter = Filter},
  +        options = Options,
  +        pending = Pending
  +    } = Acc,
       Conflicts = proplists:get_value(conflicts, Options, false),
       #doc_info{id=Id, high_seq=Seq, revs=[#rev_info{deleted=Del}|_]} = DocInfo,
  -    case [X || X <- couch_changes:filter(Db, DocInfo, Acc), X /= null] of
  +    case [X || X <- couch_changes:filter(Db, DocInfo, Filter), X /= null] of
       [] ->
  -        {ok, {Db, Seq, Args, Options}};
  +        {ok, Acc#cacc{seq = Seq, pending = Pending-1}};
       Results ->
           Opts = if Conflicts -> [conflicts]; true -> [] end,
           ChangesRow = {change, [
  +	    {pending, Pending-1},
               {seq, {Seq, uuid(Db)}},
               {id, Id},
               {changes, Results},
  
positive.code:         StartSeq = calculate_start_seq(Db, node(), StartVector),
          Enum = fun changes_enumerator/2,
          Opts = [{dir,Dir}],
          Acc0 = {Db, StartSeq, Args, Options},
          try
              {ok, {_, LastSeq, _, _}} =
                  couch_db:changes_since(Db, StartSeq, Enum, Opts, Acc0),
              rexi:reply({complete, [{seq, {LastSeq, uuid(Db)}}]})
          after
              couch_db:close(Db)
          end;
  
negative.code: -include_lib("couch/include/couch_db.hrl").
  -include_lib("couch_mrview/include/couch_mrview.hrl").
  
  -record (cacc, {
      db,
      seq,
      args,
      options,
      pending
  }).
  
  %% rpc endpoints
  %%  call to with_db will supply your M:F with a #db{} and then remaining args
  
  