   @spec decode(binary) :: {non_neg_integer, String.t, %{}}
   def decode(data) do
     <<_version, rest :: binary>> = data
-    decode_document(rest)
+    {record, <<>>} = decode_document(rest)
+    record
   end
 
   defp decode_document(data) do

        property = property(id: decode_property_id(i), data_ptr: data_ptr)
        decode_header_fields(rest, [property|acc])
      i > 0 ->
        IO.puts "About to decode header field from: #{inspect data}"
        {field_name, rest}            = decode_type(data, :string)
        {data_ptr, rest}              = decode_data_ptr(rest)
        <<data_type, rest :: binary>> = rest
        field = named_field(name: field_name, data_type: int_to_type(data_type), data_ptr: data_ptr)

        IO.puts "Decoded header field: #{inspect field}"

        decode_header_fields(rest, [field|acc])
    end

      field, acc when is_record(field, :named_field) ->
        named_field(data_type: type, data_ptr: ptr) = field

        if ptr == 0 do
          {{field, nil}, acc}
        else
          {value, rest} = decode_type(acc, type)
          {{field, value}, rest}
        end
    end
