         func in only
       end)
 
-      %{ env | requires: Enum.uniq(env.requires ++ [module.name]),
+      env = %{ env | requires: Enum.uniq(env.requires ++ [module.name]),
          functions: List.keydelete(env.functions, module.name, 0) ++ [{ module.name, functions }],
          macros: List.keydelete(env.macros, module.name, 0) ++ [{ module.name, macros }] }
     end
+
+    env
   end
 
   def add_import(env, module_name, [except: except]) do
-    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
-      true ->
-        add_import_macro(env, module_name, [except: except])
-      false ->
-        module = get_module(env, module_name)
-
-        {_, current_functions } = List.keyfind(env.functions, module.name, 0, { module.name, module.functions })
-        {_, current_macros } = List.keyfind(env.macros, module.name, 0, { module.name, module.macros })
-
-        macros = Enum.filter(current_macros, fn(mac) -> not(mac in except) end)
-        functions = Enum.filter(current_functions, fn(func) -> not(func in except) end)
-
-        %{ env | requires: env.requires ++ [module.name],
-          functions: List.keydelete(env.functions, module.name, 0) ++ [{ module.name, functions }],
-          macros: List.keydelete(env.macros, module.name, 0) ++ [{ module.name, macros }] }
-    end
+    check_for_module_existence(env, module_name)
+
+    if ElixirScript.Translator.State.is_module_loaded?(module_name) do
+      env = add_import_macro(env, module_name, [except: except])
+    end
+
+    if has_module?(env, module_name) do
+      module = get_module(env, module_name)
+      {_, current_functions } = List.keyfind(env.functions, module.name, 0, { module.name, module.functions })
+      {_, current_macros } = List.keyfind(env.macros, module.name, 0, { module.name, module.macros })
+
+      macros = Enum.filter(current_macros, fn(mac) -> not(mac in except) end)
+      functions = Enum.filter(current_functions, fn(func) -> not(func in except) end)
+
+      env = %{ env | requires: env.requires ++ [module.name],
+         functions: List.keydelete(env.functions, module.name, 0) ++ [{ module.name, functions }],
+         macros: List.keydelete(env.macros, module.name, 0) ++ [{ module.name, macros }] }
+    end
+
+    env
   end
 
   def add_require(env, module_name) do
-    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
-      true ->
-        add_require_macro(env, module_name, [])
-      false ->
-        module = get_module(env, module_name)
-        %{ env | requires: Enum.uniq(env.requires ++ [module.name]) }
-    end
+    check_for_module_existence(env, module_name)
+
+    if ElixirScript.Translator.State.is_module_loaded?(module_name) do
+      env = add_require_macro(env, module_name, [])
+    end
+
+    if has_module?(env, module_name) do
+      module = get_module(env, module_name)
+      env = %{ env | requires: Enum.uniq(env.requires ++ [module.name]) }
+    end
+
+    env
   end
 
   def add_require(env, module_name, alias_name) do
-    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
-      true ->
-        add_require_macro(env, module_name, [as: alias_name])
-      false ->
-        module = get_module(env, module_name)
-
-        %{ env | aliases: Enum.uniq(env.aliases ++ [{alias_name, module.name}]),
-           requires: Enum.uniq(env.requires ++ [module.name]) }
-    end
+    check_for_module_existence(env, module_name)
+
+    if ElixirScript.Translator.State.is_module_loaded?(module_name) do
+      env = add_require_macro(env, module_name, [as: alias_name])
+    end
+
+    if has_module?(env, module_name) do
+      module = get_module(env, module_name)
+      env = %{ env | aliases: Enum.uniq(env.aliases ++ [{alias_name, module.name}]),
+         requires: Enum.uniq(env.requires ++ [module.name]) }
+    end
+
+    env
 
   end
 

    module
  end

  def add_alias(env, module_name, alias_name) do
    module = get_module(env, module_name)
    %{ env | aliases: Enum.uniq(env.aliases ++ [{alias_name, module.name}]) }
  end

  def add_import(env, module_name) do
    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
      true ->
        add_import_macro(env, module_name, [])
      false ->
        module = get_module(env, module_name)

        %{ env | requires: Enum.uniq(env.requires ++ [module.name]),
           functions: env.functions ++ [{ module.name, module.functions }],
           macros: env.macros ++ [{ module.name, module.macros }] }
    end
  end

  def add_import(env, module_name, [only: :functions]) do
    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
      true ->
        add_import_macro(env, module_name, [only: :functions])
      false ->
        module = get_module(env, module_name)

        %{ env | functions: List.keydelete(env.functions, module_name, 0) ++ [{ module.name, module.functions }],
           macros: List.keydelete(env.macros, module.name, 0),
           requires: Enum.uniq(env.requires ++ [module.name]) }
    end
  end

  def add_import(env, module_name, [only: :macros]) do
    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
      true ->
        add_import_macro(env, module_name, [only: :macros])
      false ->
        module = get_module(env, module_name)

        %{ env | macros: List.keydelete(env.macros, module_name, 0) ++ [{ module.name, module.macros }],
           functions: List.keydelete(env.functions, module.name, 0),
           requires: Enum.uniq(env.requires ++ [module.name]) }
    end
  end

  def add_import(env, module_name, [only: only]) do
    case ElixirScript.Translator.State.is_module_loaded?(module_name) do
      true ->
        add_import_macro(env, module_name, [only: only])
      false ->
        module = get_module(env, module_name)

      macros = Enum.filter(module.macros, fn(mac) ->
        mac in only
      end)

    do_macro(eval, elixirscript_env)
  end

  defp add_require_macro(elixirscript_env, module, opts) do
    eval = """
    require #{inspect module}, #{inspect opts}
    __ENV__
