   end
   def handle_message(_, _), do: :unknown
 
-  defp handle_data(msg, %{socket: socket} = conn) do
+  defp handle_data(data, %{socket: socket} = conn) do
     :ok = activate(socket)
-    {:ok, _conn, _stanza} = parse_stanza(conn, msg)
+    {:ok, _conn, _stanza} = parse_data(conn, data)
   end
 
   defp activate({:gen_tcp, socket}) do

  def recv({:ok, conn}, fun), do: recv(conn, fun)
  def recv(%Conn{socket: {:gen_tcp, socket}, timeout: timeout} = conn, fun) do
    receive do
      {:tcp, ^socket, stanza} ->
        :inet.setopts(socket, active: :once)
        {:ok, conn, stanzas} = parse_stanza(conn, stanza)
        fun.(conn, stanzas)
      {:tcp_closed, ^socket} ->
        {:error, :closed}
      {:tcp_error, ^socket, reason} ->
        {:error, reason}
    after timeout ->
      _ = Kernel.send(self, {:error, :timeout})
      conn
    end
  end
  def recv(%Conn{socket: {:ssl, socket}, timeout: timeout} = conn, fun) do
    receive do
      {:ssl, ^socket, stanza} ->
        :ssl.setopts(socket, active: :once)
        {:ok, conn, stanzas} = parse_stanza(conn, stanza)
        fun.(conn, stanzas)
      {:ssl_closed, ^socket} ->
        {:error, :closed}
      {:ssl_error, ^socket, reason} ->
        {:error, reason}
    after timeout ->
      _ = Kernel.send(self, {:error, :timeout})
      conn
    end
  end

    |> ready
  end

  defp start_stream(%Conn{jid: jid, socket: {mod, socket}} = conn) do
    stanza = jid |> host |> Romeo.Stanza.start_stream

    conn
    |> send(stanza)
    |> recv(fn
      conn, [xmlstreamstart(), xmlel(name: "stream:features") = features | []] ->
        Kernel.send(self, {tcp_tag(mod), socket, features})
        conn
      conn, [xmlstreamstart() | []] ->
        conn
    end)
  end

  defp negotiate_features(%Conn{} = conn) do
