anchor.diff:  write_propagated_values(IO, Header, Lower, LowerInterval, Values, NumPoints) ->
       AggType = Header#metadata.aggregation,
       XFF = Header#metadata.xff,
  -    KnownPercentage = length(Values) / NumPoints,
  +    NumValues = length(Values),
  +    KnownPercentage = NumValues / NumPoints,
       if
           % we do have enough data points to calculate an aggregation
           KnownPercentage >= XFF ->
  -            AggValue = aggregate(AggType, Values, NumPoints),
  +            AggValue = aggregate(AggType, Values, NumValues, NumPoints),
               lager:info("calculated aggregate [~p] ~p [values ~p]", [AggType, AggValue, Values]),
               Point = data_point(LowerInterval, AggValue),
               {BaseInterval, _} = point_at(IO, Lower#archive_header.offset),
               Offset = get_data_point_offset(Lower, LowerInterval, BaseInterval),
  -            {ok, _} = file:position(IO, {bof, Offset}),
  -            ok = file:write(IO, Point),
  +            ok = write_at(IO, Point, Offset),
               true;
           true ->
               false
       end.
   
   
  -aggregate(average, Values, _) -> lists:sum(Values) / length(Values);
  -aggregate(sum, Values, _) -> lists:sum(Values);
  -aggregate(last, Values, _) -> lists:last(Values);
  -aggregate(max, Values, _) -> lists:max(Values);
  -aggregate(min, Values, _) -> lists:min(Values);
  -aggregate(average_zero, Values, NumPoints) -> lists:sum(Values) / NumPoints.
  +aggregate(average, Values, NumValues, _) -> lists:sum(Values) / NumValues;
  +aggregate(sum, Values, _, _) -> lists:sum(Values);
  +aggregate(last, Values, _, _) -> lists:last(Values);
  +aggregate(max, Values, _, _) -> lists:max(Values);
  +aggregate(min, Values, _, _) -> lists:min(Values);
  +aggregate(average_zero, Values, _, NumPoints) -> lists:sum(Values) / NumPoints.
   
   
   write_point(IO, Header, Value, TimeStamp) ->
  
positive.code: 
  collect_series_values(Step, Interval, <<TS:32/integer-unsigned-big, Value:64/float-big, Rst/binary>>, Acc, Seen) ->
      if
          Interval == TS ->
              collect_series_values(Step, Interval + Step, Rst, [Value | Acc], Seen + 1);
          true ->
  
negative.code: 
      WroteAggregate = write_propagated_values(IO, Header, Lower, LowerStart, CollectedValues, NumPoints),
      if
          % continue to write into even lower archives only if we actually
          % wrote an aggregate value in this archive
          WroteAggregate == true ->
              propagate_lower_archives(IO, Header, TimeStamp, Lower, Ls);
          true ->
  