diff --git a/src/dht.cpp b/src/dht.cpp
index 6b93871ca681469f3baa9e0ad08608e0a7ed7bb7..2619ed2e3648873f74ad7d795c851b78bc27c58e 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -2883,11 +2883,11 @@ Dht::~Dht()
 Dht::Dht() : store(), scheduler(DHT_LOG), network_engine(DHT_LOG, scheduler) {}
 
 Dht::Dht(int s, int s6, Config config)
- : myid(config.node_id),
-   is_bootstrap(config.is_bootstrap),
-   maintain_storage(config.maintain_storage), store(), store_quota(),
-   scheduler(DHT_LOG),
-   network_engine(myid, config.network, s, s6, DHT_LOG, scheduler,
+    : myid(config.node_id != zeroes ? config.node_id : InfoHash::getRandom()),
+    is_bootstrap(config.is_bootstrap),
+    maintain_storage(config.maintain_storage), store(), store_quota(),
+    scheduler(DHT_LOG),
+    network_engine(myid, config.network, s, s6, DHT_LOG, scheduler,
             std::bind(&Dht::onError, this, _1, _2),
             std::bind(&Dht::onNewNode, this, _1, _2),
             std::bind(&Dht::onReportedAddr, this, _1, _2),
diff --git a/src/securedht.cpp b/src/securedht.cpp
index d9bcfc5424d3a5209b3366941efa7dc1d63abab2..7642fec9fb763d856581468af46db73511e6acbb 100644
--- a/src/securedht.cpp
+++ b/src/securedht.cpp
@@ -36,12 +36,8 @@ namespace dht {
 Config& getConfig(SecureDht::Config& conf)
 {
     auto& c = conf.node_config;
-    if (c.node_id == InfoHash()) {
-          if (conf.id.second)
-            c.node_id = InfoHash::get("node:"+conf.id.second->getId().toString());
-        else
-            c.node_id = InfoHash::getRandom();
-    }
+    if (c.node_id == InfoHash() and conf.id.second)
+        c.node_id = InfoHash::get("node:"+conf.id.second->getId().toString());
     return c;
 }