diff --git a/src/dht.cpp b/src/dht.cpp
index e9ca0453c931d01cf6c8b833f2c9d0aa9a8be284..e673724a41a3b980c1d63154ab611c7f8104dee3 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -1213,7 +1213,6 @@ void Dht::searchSendAnnounceValue(const std::shared_ptr<Search>& sr) {
                                             sr->af == AF_INET ? '4' : '6',
                                             sn->node->toString().c_str(),
                                             a.value->id);
-                                    /* TODO: kind of a hack. Other solution? */
                                     auto ack_req = std::make_shared<Request>();
                                     ack_req->reply_time = now;
                                     sn->acked[a.value->id] = std::move(ack_req);
@@ -1302,8 +1301,7 @@ Dht::searchStep(std::shared_ptr<Search> sr)
 
                         std::weak_ptr<Search> ws = sr;
                         n.listenStatus[query] = network_engine.sendListen(n.node, sr->id, *query, n.token,
-                            [this,ws,last_req,query](const Request& req,
-                                    NetworkEngine::RequestAnswer&& answer) mutable
+                            [this,ws,last_req,query](const Request& req, NetworkEngine::RequestAnswer&& answer) mutable
                             { /* on done */
                                 network_engine.cancelRequest(last_req);
                                 if (auto sr = ws.lock()) {
@@ -3008,20 +3006,18 @@ Dht::pingNode(const sockaddr* sa, socklen_t salen)
 void
 Dht::onError(std::shared_ptr<Request> req, DhtProtocolException e) {
     if (e.getCode() == DhtProtocolException::UNAUTHORIZED) {
+        DHT_LOG.ERR("[node %s] token flush", req->node->toString().c_str());
         network_engine.cancelRequest(req);
-        unsigned cleared = 0;
         for (auto& srp : req->node->getFamily() == AF_INET ? searches4 : searches6) {
             auto& sr = srp.second;
             for (auto& n : sr->nodes) {
                 if (n.node != req->node) continue;
                 n.token.clear();
                 n.last_get_reply = time_point::min();
-                cleared++;
                 searchSendGetValues(sr);
                 break;
             }
         }
-        DHT_LOG.WARN("[node %s] token flush (%d searches affected)", req->node->toString().c_str(), cleared);
     }
 }
 
diff --git a/src/network_engine.cpp b/src/network_engine.cpp
index 8d69afa5702700bfe065b628f8c48cf34c75d031..f0e8c4012392825d605fed68f7db159760bb2c72 100644
--- a/src/network_engine.cpp
+++ b/src/network_engine.cpp
@@ -64,23 +64,23 @@ enum class MessageType {
 
 struct ParsedMessage {
     MessageType type;
-    InfoHash id;                                              /* the id of the sender */
-    NetId network {0};                                 /* network id */
-    InfoHash info_hash;                                       /* hash for which values are requested */
-    InfoHash target;                                          /* target id around which to find nodes */
-    NetworkEngine::TransId tid;                               /* transaction id */
-    Blob token;                                               /* security token */
-    Value::Id value_id;                                       /* the value id */
-    time_point created { time_point::max() };                 /* time when value was first created */
-    Blob nodes4_raw, nodes6_raw;                              /* IPv4 nodes in response to a 'find' request */
+    InfoHash id;                                          /* the id of the sender */
+    NetId network {0};                                    /* network id */
+    InfoHash info_hash;                                   /* hash for which values are requested */
+    InfoHash target;                                      /* target id around which to find nodes */
+    NetworkEngine::TransId tid;                           /* transaction id */
+    Blob token;                                           /* security token */
+    Value::Id value_id;                                   /* the value id */
+    time_point created { time_point::max() };             /* time when value was first created */
+    Blob nodes4_raw, nodes6_raw;                          /* IPv4 nodes in response to a 'find' request */
     std::vector<std::shared_ptr<Node>> nodes4, nodes6;
-    std::vector<std::shared_ptr<Value>> values;               /* values for a 'get' request */
+    std::vector<std::shared_ptr<Value>> values;           /* values for a 'get' request */
     std::vector<std::shared_ptr<FieldValueIndex>> fields; /* index for fields values */
-    Query query;                                              /* query describing a filter to apply on values. */
-    want_t want;                                              /* states if ipv4 or ipv6 request */
-    uint16_t error_code;                                      /* error code in case of error */
+    Query query;                                          /* query describing a filter to apply on values. */
+    want_t want;                                          /* states if ipv4 or ipv6 request */
+    uint16_t error_code;                                  /* error code in case of error */
     std::string ua;
-    SockAddr addr;                                            /* reported address by the distant node */
+    SockAddr addr;                                        /* reported address by the distant node */
     void msgpack_unpack(msgpack::object o);
 };
 
@@ -824,12 +824,14 @@ NetworkEngine::sendListen(std::shared_ptr<Node> n, const InfoHash& infohash, con
     msgpack::packer<msgpack::sbuffer> pk(&buffer);
     pk.pack_map(5+(network?1:0));
 
-    pk.pack(std::string("a")); pk.pack_map(3 +
-                               (query.where.getFilter() or not query.select.getSelection().empty() ? 1:0));
+    auto has_query = query.where.getFilter() or not query.select.getSelection().empty();
+    pk.pack(std::string("a")); pk.pack_map(3 + has_query);
       pk.pack(std::string("id"));    pk.pack(myid);
       pk.pack(std::string("h"));     pk.pack(infohash);
-      pk.pack(std::string("q")); pk.pack(query);
       pk.pack(std::string("token")); packToken(pk, token);
+      if (has_query) {
+          pk.pack(std::string("q")); pk.pack(query);
+      }
 
     pk.pack(std::string("q")); pk.pack(std::string("listen"));
     pk.pack(std::string("t")); pk.pack_bin(tid.size());