DNS: Refactoring & bugfixes