 
       # Internal handler for Any
       if @fallback_to_any do
-        Kernel.defp any_impl_for(), do: __MODULE__.Any.__impl__(:target)
+        Kernel.defp(any_impl_for(), do: __MODULE__.Any.__impl__(:target))
       else
-        Kernel.defp any_impl_for(), do: nil
+        Kernel.defp(any_impl_for(), do: nil)
       end
 
       # Internal handler for Structs
       Kernel.defp struct_impl_for(struct) do
         target = Module.concat(__MODULE__, struct)
+
         case impl_for?(target) do
-          true  -> target.__impl__(:target)
+          true -> target.__impl__(:target)
           false -> any_impl_for()
         end
       end
 
       # Check if compilation is available internally
       Kernel.defp impl_for?(target) do
-        Code.ensure_compiled?(target) and
-          function_exported?(target, :__impl__, 1)
+        Code.ensure_compiled?(target) and function_exported?(target, :__impl__, 1)
       end
 
       # Inline any and struct implementations

  # Change the debug information to the optimized
  # impl_for/1 dispatch version.
  defp change_debug_info({protocol, any, code}, types) do
    types   = if any, do: types, else: List.delete(types, Any)
    all     = [Any] ++ for {_guard, mod} <- __builtin__(), do: mod
    structs = types -- all
    case change_impl_for(code, protocol, types, structs, false, []) do
      {:ok, ret} -> {:ok, ret}
      other      -> other
    end
  end

  defp change_impl_for([{:function, line, :__protocol__, 1, clauses} | tail], protocol, types, structs, _, acc) do
    abstract_types = :erl_parse.abstract(:lists.usort(types))

    clauses = :lists.map(fn
      {:clause, l, [{:atom, _, :consolidated?}], [], [{:atom, _, _}]} ->
        {:clause, l, [{:atom, 0, :consolidated?}], [], [{:atom, 0, true}]}
      {:clause, l, [{:atom, _, :impls}], [], [{:atom, _, _}]} ->
        {:clause, l, [{:atom, 0, :impls}], [], [{:tuple, 0, [{:atom, 0, :consolidated}, abstract_types]}]}
      {:clause, _, _, _, _} = c ->
        c
    end, clauses)

    change_impl_for(tail, protocol, types, structs, true,
                    [{:function, line, :__protocol__, 1, clauses} | acc])
  end

  defp change_impl_for([{:function, line, :impl_for, 1, _} | tail], protocol, types, structs, protocol?, acc) do
    fallback = if Any in types, do: load_impl(protocol, Any)

    clauses = for {guard, mod} <- __builtin__(),
                  mod in types,
                  do: builtin_clause_for(mod, guard, protocol, line)

    clauses = [struct_clause_for(line) | clauses] ++
              [fallback_clause_for(fallback, protocol, line)]

    change_impl_for(tail, protocol, types, structs, protocol?,
                    [{:function, line, :impl_for, 1, clauses} | acc])
  end

  defp change_impl_for([{:function, line, :struct_impl_for, 1, _} | tail], protocol, types, structs, protocol?, acc) do
    fallback = if Any in types, do: load_impl(protocol, Any)
    clauses = for struct <- structs, do: each_struct_clause_for(struct, protocol, line)
    clauses = clauses ++ [fallback_clause_for(fallback, protocol, line)]

    change_impl_for(tail, protocol, types, structs, protocol?,
                    [{:function, line, :struct_impl_for, 1, clauses} | acc])
  end

  defp change_impl_for([{:attribute, line, :spec, {{:__protocol__, 1}, funspecs}} | tail], protocol, types, structs, protocol?, acc) do
    new_specs = for spec <- funspecs do
      case spec do
        {:type, line, :fun, [{:type, _, :product, [{:atom, _, :consolidated?}]}, _]} ->
          {:type, line, :fun,
           [{:type, line, :product, [{:atom, 0, :consolidated?}]},
            {:atom, 0, true}]}
        {:type, line, :fun, [{:type, _, :product, [{:atom, _, :impls}]}, _]} ->
          impls = for mod <- types, do: {:atom, 0, mod}
          {:type, line, :fun,
           [{:type, line, :product, [{:atom, 0, :impls}]},
            {:type, 0, :tuple,
             [{:atom, 0, :consolidated},
              {:type, 0, :list, [{:type, 0, :union, impls}]}]}]}
        other -> other
      end
    end
    change_impl_for(tail, protocol, types, structs, protocol?, [{:attribute, line, :spec, {{:__protocol__, 1}, new_specs}} | acc])
  end

  defp change_impl_for([head | tail], protocol, info, types, protocol?, acc) do

        @spec __impl__(:for) :: unquote(for)
        @spec __impl__(:target) :: __MODULE__
        @spec __impl__(:protocol) :: unquote(protocol)
        def __impl__(:for), do: unquote(for)
        def __impl__(:target), do: __MODULE__
        def __impl__(:protocol), do: unquote(protocol)
      end

    quote do
      protocol = unquote(protocol)
      for = unquote(for)
      name = Module.concat(protocol, for)

      Protocol.assert_protocol!(protocol)
      Protocol.__ensure_defimpl__(protocol, for, __ENV__)

      defmodule name do
        @behaviour protocol
        @protocol protocol
        @for for

        unquote(block)

