 
   def add_protocol_impl(protocol, type, impl) do
     Agent.update(__MODULE__, fn state ->
-      proto = do_get_module(state, protocol)
+      proto = Map.get(state.modules, do_get_module_name(protocol, state))
 
       if proto == nil do
         proto = %ElixirScript.Module{ name: protocol, impls: HashDict.new, type: :protocol }

defmodule ElixirScript.Translator.State do
  @moduledoc false
  alias ElixirScript.Translator.Utils

  @doc """
  This agent holds references to the compiler options, a map all of the modules, and
  a map of modules that define the standard library.

  The modules map has the module's name a the key and a ElixirScript.Module struct as the value.
  The module struct contains properties to access the function and macro names/arities

  """
  def start_link(compiler_opts \\ []) do
    Agent.start_link(fn ->
      %{ compiler_opts: compiler_opts, modules: Map.new, std_lib_map: build_standard_lib_map() }

  end

  def get_module_name(module_name) do
    Agent.get(__MODULE__, fn(state) ->
      do_get_module_name(module_name, state)
    end)
  end

  defp do_get_module_name(module_name, state) do
    std_lib_map = state.std_lib_map
    case Map.get(std_lib_map, module_name) do
      nil ->
