             {:error, {:already_registered, pid}}
           else
             :ets.delete_object(key_ets, current)
-            register_key(:unique, pid_server, key_ets, key, entry)
+            register_key(:unique, key_ets, key, entry)
           end
 
         [] ->
-          register_key(:unique, pid_server, key_ets, key, entry)
+          register_key(:unique, key_ets, key, entry)
       end
     end
   end

    counter = System.unique_integer()
    true = :ets.insert(pid_ets, {self, key, key_ets, counter})

    case register_key(kind, pid_server, key_ets, key, {key, {self, value}}) do
      {:ok, _} = ok ->
        for listener <- listeners do
          Kernel.send(listener, {:register, registry, key, self, value})
        end

        ok

      {:error, {:already_registered, ^self}} = error ->
        true = :ets.delete_object(pid_ets, {self, key, key_ets, counter})

    end
  end

  defp register_key(:duplicate, key_ets, _key, entry) do
    true = :ets.insert(key_ets, entry)
    :ok
  end

  defp register_key(:unique, key_ets, key, entry) do
    if :ets.insert_new(key_ets, entry) do
      :ok
    else
      # Notice we have to call register_key recursively
      # because we are always at odds of a race condition.
