   end
 
   def handle_execute(_query, frame, _opts, %{sock: sock} = state) do
-    case :gen_tcp.send(sock, frame) do
-      :ok ->
-        {:ok, recv_result(sock), state}
+    with :ok <- :gen_tcp.send(sock, frame),
+        {:ok, response} <- recv_response(sock) do
+      {:ok, response, state}
+    else
       {:error, reason} ->
         {:disconnect, reason, state}
     end

    end
  end

  defp recv_result(sock) do
    case :gen_tcp.recv(sock, 9) do
      {:ok, header} ->
        case Frame.body_length(header) do
          0 ->
            {header, <<>>}
          length ->
            with {:ok, body} <- :gen_tcp.recv(sock, length) do
              {header, body}
            end
        end
      {:error, _reason} = error ->
        error
    end
  end
end


  def handle_close(query, _opts, state) do
    {:ok, query, state}
  end

  def disconnect(_exception, %{sock: sock}) do
    :ok = :gen_tcp.close(sock)
  end

  defp startup_connection(sock, %{"CQL_VERSION" => [cql_version | _]}) do
