   defp insert_annotations({:error, changeset}, _), do: {:error, changeset}
   defp insert_annotations({:ok, fact}, changeset) do
     Ecto.Changeset.get_field(changeset, :annotations)
-    |> Enum.map(create_changeset(fact_id))
-    |> Enum.reduce(&insert_annotation/2)
+    |> Enum.map(create_changeset(fact.id))
+    |> Enum.reduce({:ok, fact, []}, &insert_annotation/2)
   end
 
   defp remove_annotations({:error, changeset}, _), do: {:error, changeset}
-  defp remove_annotations({:ok, fact}, changeset) do
+  defp remove_annotations({:ok, fact}, _) do
     query = from(fa in FactAnnotation, where: fa.fact_id == ^fact.id)
 
     Repo.delete_all(query)

  def show(conn, _) do
    fact = conn.assigns[:fact]
    |> Repo.preload(:question)
    |> Repo.preload(:annotations)

    render(conn, "show.json", fact: fact)
  end

  def update(conn, fact_params) do
    fact = conn.assigns[:fact]
    changeset = Fact.changeset(fact, fact_params)

    case Repo.update(changeset) do
      {:ok, fact} ->
        fact = fact
        |> Repo.preload(:question)
        |> Repo.preload(:annotations)

        render(conn, "show.json", fact: fact)
      {:error, changeset} ->

  def create(conn, fact_params) do
    changeset = Fact.changeset(%Fact{}, fact_params)

    case insert_fact_and_annotations(changeset) do
      {:ok, fact} ->
        fact = fact
        |> Repo.preload(:question)
        |> Repo.preload(:fact_annotations)

        conn
        |> put_status(:created)
