dht: improve code organization