Refactoring DHT code