anchor.diff:  
   %% @doc Get the latest samples for a given interval from the archive
   latest(Period, Node, Bucket) when is_atom(Node) ->
  -    [{Node, Result}] = latest(Period, [Node], Bucket),
  +    {atomic, Result} = mnesia:transaction(
  +                         fun () ->
  +                                 Tab = table(Node, Bucket, Period),
  +                                 Key = mnesia:last(Tab),
  +                                 hd(mnesia:read(Tab, Key))
  +                         end),
       Result;
   latest(Period, Nodes, Bucket) when is_list(Nodes), is_list(Bucket) ->
       misc:pmap(fun (Node) ->
  -                      {Node, mnesia:transaction(
  -                               fun () ->
  -                                       Tab = table_name(Node, Bucket, Period),
  -                                       Key = mnesia:last(Tab),
  -                                       hd(mnesia:read(Tab, Key))
  -                               end)}
  +                      {Node, latest(Period, Node, Bucket)}
                 end, Nodes, length(Nodes)).
   
   
   latest(Period, Node, Bucket, N) when is_atom(Node), is_list(Bucket) ->
  -    [{Node, Results}] = latest(Period, [Node], Bucket, N),
  -    Results;
  +    walk(table(Node, Bucket, Period), N);
   latest(Period, Nodes, Bucket, N) when is_list(Nodes), is_list(Bucket) ->
       misc:pmap(fun (Node) ->
  -                      {Node, walk(table_name(Node, Bucket, Period), N)}
  +                      {Node, latest(Period, Node, Bucket, N)}
                 end, Nodes, length(Nodes)).
  +
  +
  +latest(Period, Nodes, Bucket, Step, N) when is_list(Nodes) ->
  +    misc:pmap(fun (Node) ->
  +                      {Node, latest(Period, Node, Bucket, Step, N)}
  +              end, Nodes, length(Nodes));
  +latest(Period, Node, Bucket, Step, N) when is_atom(Node) ->
  +    resample(table(Node, Bucket, Period), Step, N).
   
   
   latest_all(Period, Bucket) ->
  
positive.code: 
  
  %% @doc Generate a suitable name for the Mnesia table.
  table_name(Node, Bucket, Period) ->
      list_to_atom(lists:flatten(io_lib:format("~s-~s-~s-~s",
                                               [?MODULE_STRING,
                                                Node, Bucket, Period]))).
  
  
  %% @doc Truncate the given table to the last N records.
  
negative.code:     list_to_tuple([stat_entry, TS | List]).
  
  
  %% @doc Resample the stats in a table. Only reads the necessary number of rows.
  resample(Tab, Step, N) ->
      {atomic, Result} = mnesia:transaction(
                           fun () ->
                                   TS = mnesia:last(Tab),
                                   resample(Tab, Step, TS, trunc_ts(TS, Step), [],
                                            [], N)
                           end),
      Result.
  
  
  resample(_, _, TS, _, Acc, [], N) when TS == '$end_of_table'; N == 0 ->
      Acc;
  resample(_, _, _, _, Acc, _, 0)  ->
      Acc;
  resample(_, _, '$end_of_table', T, Acc, Chunk, _) ->
      [avg(T, Chunk)|Acc];
  resample(Tab, Step, TS, T, Acc, Chunk, N) ->
      T1 = trunc_ts(TS, Step),
      [Rec] = mnesia:read(Tab, TS),
      Prev = mnesia:prev(Tab, TS),
      case T of
          T1 ->
              resample(Tab, Step, Prev, T1, Acc, [Rec|Chunk], N);
          _ ->
              resample(Tab, Step, Prev, T1, [avg(T, Chunk)|Acc], [], N-1)
      end.
  
  
  %% @doc Generate a suitable name for the per-bucket gen_server.
  