refactor DNS logic; fix some bugs in reverse-resolution