   def query_peers(command) do
     ExLog.info "querying peers for #{command}"
     Erlang.dnssd.browse(__MODULE__.__info__(:data)[:service_type])
-    query_peers command, [], Erlang.sets.new()
+    query_peers command, [], Erlang.sets.new(), Erlang.dict.new()
   end
 
-  defp query_peers(command, data, seen_already) do
+  defp query_peers(command, data, seen_already, conn_lookup) do
     receive do
     match: {:dnssd, _ref, {:browse, :add, response={name, type, domain}}}
       # Found a peer, now get the port that it's listening on
       Erlang.dnssd.resolve name, type, domain
-      query_peers command, data, seen_already
+      query_peers command, data, seen_already, conn_lookup
     match: {:dnssd, _ref, {:resolve, response={domain_dot, port, _dns_data}}}
       # Resolved the port of a peer, now connect to it and send the query
       domain = binary_to_list(Regex.replace(%r/\.$/, domain_dot, ""))

    timeout = 10000
    case transport.recv(socket, 0, timeout) do
    match: {:ok, data}
      response = inspect(CerebrateChecks.get_all())
      ExLog.info "received data: #{data}, responding with #{inspect(response)}"
      case transport.send(socket, response) do
      match: :ok
        :ok
      match: {:error, reason}
        ExLog.info "Send error: #{inspect(reason)}"
      end
    match: {:error, reason}
      ExLog.info "Error: #{inspect reason}"
      transport.close(socket)
    end
  end
end



      case Erlang.sets.is_element(conn, seen_already) do
      match: :true
        ExLog.info "Skipping #{inspect(conn)}"
        query_peers command, data, seen_already, conn_lookup
      match: :false
        ExLog.info "Connecting to #{inspect(conn)}"
        {:ok, socket} = Erlang.gen_tcp.connect domain, port, [:binary, {:active, :true}]      
        Erlang.gen_tcp.send socket, command
        query_peers command, data, Erlang.sets.add_element(conn, seen_already), Erlang.dict.store(socket, conn, conn_lookup)
      end
    match: {:tcp, socket, new_data}
      # Received new data from a peer, append it to the list
      {domain, port} = Erlang.dict.fetch(socket, conn_lookup)
      conn = [list_to_binary(domain), list_to_binary(integer_to_list(port))]
      ExLog.info "received new data: #{inspect(new_data)} from #{inspect(conn)}"
      query_peers command, [[conn, new_data] | data], seen_already, conn_lookup
    match: {:tcp_closed, _port}
      # A peer closed the socket, probably ok
      query_peers command, data, seen_already, conn_lookup
    after: __MODULE__.__info__(:data)[:browse_timeout]
      # No messages after a few milliseconds, assume that everyone has 
      # reported in and return the data. 
