     end)
   end
 
+  # Update annotation and tags
+  defp update_annotation_and_tags(changeset) do
+    tags = Ecto.Changeset.get_field(changeset, :tags)
+
+    Repo.transaction(fn ->
+      result = Repo.update(changeset)
+      |> remove_tags()
+      |> add_tags(tags)
+
+      case result do
+        {:error, changeset} ->
+          Repo.rollback(changeset)
+
+        {:ok, annotation, tags} ->
+          Map.merge(annotation, %{tags: tags})
+      end
+    end)
+  end
+
   # Add tags to an annotation
   #
   # Returns a {:ok, tags} or {:error, changeset} tuple

        {:error, changeset}
    end
  end
end

    |> Enum.reduce({:ok, annotation, []}, &add_tag/2)
  end

  # Add a tag into a annotation
  defp add_tag(_, {:error, changeset}), do: {:error, changeset}
  defp add_tag(changeset = %{valid?: valid}, {:ok, _, _}) when not valid do
    {:error, changeset}
