Refactored DHT.c

This is the DHT.c refactoring from yesterday, I've spread it across these 8 commits, editing a few hundred lines each.