           {:error, :model, changeset, %{}} ->
             filtered_changes = Map.drop(changeset.changes, [:current_version_id])
             {:error, Map.merge(changeset, %{repo: repo, changes: filtered_changes})}
-          {:ok, map} -> {:ok, Map.delete(map, :initial_version)}
+
+          {:ok, map} ->
+            {:ok, Map.delete(map, :initial_version)}
         end
+
       _ ->
         case transaction do
           {:error, :model, changeset, %{}} -> {:error, Map.merge(changeset, %{repo: repo})}

  """
  def delete!(struct, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do
    repo = PaperTrail.RepoClient.repo()
    repo.transaction(fn ->
      model = repo.delete!(struct, options)
      version_struct = make_version_struct(%{event: "delete"}, struct, options)
      repo.insert!(version_struct, options)
      model
    end) |> elem(1)
  end

  defp make_version_struct(%{event: "insert"}, model, options) do
    originator = PaperTrail.RepoClient.originator()
    originator_ref = options[originator[:name]] || options[:originator]
    %Version{
      event: "insert",
      item_type: model.__struct__ |> Module.split |> List.last,
      item_id: model.id,
      item_changes: serialize(model),
      originator_id: case originator_ref do
        nil -> nil
        _ -> originator_ref |> Map.get(:id)
      end,
      origin: options[:origin],
      meta: options[:meta]
    } |> add_prefix(options[:prefix])
  end
  defp make_version_struct(%{event: "update"}, changeset, options) do
    originator = PaperTrail.RepoClient.originator()
    originator_ref = options[originator[:name]] || options[:originator]
    %Version{
      event: "update",
      item_type: changeset.data.__struct__ |> Module.split |> List.last,
      item_id: changeset.data.id,
      item_changes: changeset.changes,
      originator_id: case originator_ref do
        nil -> nil
        _ -> originator_ref |> Map.get(:id)
      end,
      origin: options[:origin],
      meta: options[:meta]
    } |> add_prefix(options[:prefix])
  end
  defp make_version_struct(%{event: "delete"}, model, options) do
    originator = PaperTrail.RepoClient.originator()
    originator_ref = options[originator[:name]] || options[:originator]
    %Version{
      event: "delete",
      item_type: model.__struct__ |> Module.split |> List.last,
      item_id: model.id,
      item_changes: serialize(model),
      originator_id: case originator_ref do
        nil -> nil
        _ -> originator_ref |> Map.get(:id)
      end,
      origin: options[:origin],
      meta: options[:meta]
    } |> add_prefix(options[:prefix])
  end

  defp get_sequence_from_model(changeset) do
    table_name = case Map.get(changeset, :data) do
      nil -> changeset.__struct__.__schema__(:source)
      _ -> changeset.data.__struct__.__schema__(:source)
    end
    get_sequence_id(table_name)
  end

  defp get_sequence_id(table_name) do
    Ecto.Adapters.SQL.query!(RepoClient.repo(), "select last_value FROM #{table_name}_id_seq").rows
    |> List.first
    |> List.first
  end

  defp serialize(model) do

  """
  def delete(struct, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do
    repo = PaperTrail.RepoClient.repo()

    transaction =
      Multi.new()
      |> Multi.delete(:model, struct, options)
      |> Multi.run(:version, fn %{} ->
        version = make_version_struct(%{event: "delete"}, struct, options)
