         end
     end
 
-    Enum.map(changes.tags, tag_id_to_changeset)
+    Enum.map(Ecto.Changeset.get_field(changeset, :answer), tag_id_to_changeset)
     |> Enum.reduce({:ok, question, []}, insert_changeset)
   end
+
+  defp remove_tags({:error, changeset}, _), do: {:error, changeset}
+  defp remove_tags({:ok, question}, _) do
+    query = from(qt in QuestionTag, where: qt.question_id == ^question.id)
+    Repo.delete_all(query)
+
+    {:ok, question}
+  end
 end

    |> Repo.preload(:question_tags)

    changeset = Question.changeset(
      Map.merge(question, %{tags: question.question_tags}),
      question_params)

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

        render(conn, "show.json", question: question)
      {:error, changeset} ->
        conn
        |> put_status(:unprocessable_entity)

    end)
  end

  defp update_question_and_tags(changeset) do
    Repo.transaction(fn ->
      case (Repo.update(changeset) |> remove_tags(changeset) |> insert_tags(changeset)) do
        {:error, changeset} ->
          Repo.rollback(changeset)
        {:ok, question, tags} ->
          Map.merge(question, %{tags: tags})
      end
    end)
  end

  defp insert_tags({:error, changeset}, _), do: {:error, changeset}
  defp insert_tags({:ok, question}, changeset) do
    tag_id_to_changeset = fn answer ->
      QuestionTag.changeset(%QuestionTag{}, %{"tag_id" => answer["tag"],
                                              "required" => answer["required"],
                                              "question_id" => question.id})
    end

    insert_changeset = fn
