anchor.diff:          L :: [ parsed_field() ] ) ->
       { Found ::[ piqirun_return_buffer() ], Rest :: [ parsed_field() ]}.
   
  -% find record fields by code
  +% find all fields with the given code in the list of fields sorted by codes
   find_fields(Code, L) ->
  -    {RevRes, Rest} = find_fields_rev(Code, L),
  -    {lists:reverse(RevRes), Rest}.
  -
  -
  -% find record fields by code and return the list of found fields in reverse
  -% order
  -find_fields_rev(Code, L) ->
  -    find_fields_rev(Code, L, [], []).
  -
  -
  -find_fields_rev(_Code, [], Accu, Rest) ->
  -    {Accu, lists:reverse(Rest)};
  -find_fields_rev(Code, [{Code, X} | T], Accu, Rest) ->
  -    find_fields_rev(Code, T, [X | Accu], Rest);
  -find_fields_rev(Code, [H | T], Accu, Rest) ->
  -    find_fields_rev(Code, T, Accu, [H | Rest]).
  +    find_fields(Code, L, _Accu = []).
  +
  +
  +find_fields(Code, [{Code, Value} | T], Accu) ->
  +    find_fields(Code, T, [Value | Accu]);
  +find_fields(Code, [{NextCode, _} | T], Accu) when NextCode < Code ->
  +    % skipping the field which code is less than the requested one
  +    find_fields(Code, T, Accu);
  +find_fields(_Code, Rest, Accu) ->
  +    {lists:reverse(Accu), Rest}.
  +
  +
  +-spec find_field/2 :: (
  +        Code :: pos_integer(),
  +        L :: [ parsed_field() ] ) ->
  +    { Found :: 'undefined' | piqirun_return_buffer(), Rest :: [ parsed_field() ]}.
  +
  +% find the last instance of a field given its code in the list of fields sorted
  +% by codes
  +find_field(Code, [{Code, Value} | T]) ->
  +    % check if this is the last instance of it, if not, continue iterating
  +    % through the list
  +    try_find_next_field(Code, Value, T);
  +find_field(Code, [{NextCode, _Value} | T]) when NextCode < Code ->
  +    % skipping the field which code is less than the requested one
  +    find_field(Code, T);
  +find_field(_Code, Rest) -> % not found
  +    {'undefined', Rest}.
  +
  +
  +try_find_next_field(Code, _PrevValue, [{Code, Value} | T]) ->
  +    % field is found again
  +    try_find_next_field(Code, Value, T);
  +try_find_next_field(_Code, PrevValue, Rest) ->
  +    % previous field was the last one
  +    {PrevValue, Rest}.
   
   
   -spec throw_error/1 :: (any()) -> no_return().
  
positive.code: 
  
  parse_record_buf(Bytes) ->
      parse_record_buf(Bytes, []).
  
  parse_record_buf(<<>>, Accu) ->
      lists:reverse(Accu);
  parse_record_buf(Bytes, Accu) ->
      {Value, Rest} = parse_field(Bytes),
      parse_record_buf(Rest, [Value | Accu]).
  
  
  parse_variant(X) ->
  
negative.code: 
  
  parse_optional_field(Code, ParseValue, L) ->
      {Field, Rest} = find_field(Code, L),
      Res = 
          case Field of
              'undefined' -> 'undefined';
              X ->
                  % NOTE: handling field duplicates without failure
                  % XXX, TODO: produce a warning
                  ParseValue(X)
  