         do: var_name
   end
 
-  defp loop_state(server, history, opts) do
+  defp loop_state(ref, server, history, opts) do
     env = opts[:env] || :elixir.env_for_eval(file: "iex")
     env = %{env | prematch_vars: :apply}
     {_, _, env} = :elixir.eval_quoted(quote(do: import(IEx.Helpers)), [], env)

        loop(state)

      {:done, ^server} ->
        :ok
    end
  end

    end
  end

  defp loop(%{server: server, ref: ref} = state) do
    receive do
      {:eval, ^server, code, iex_state} ->
        {result, state} = eval(code, iex_state, state)
