Refactoring for better modularity.

* Using `pegs` module for matching `dig` output.
* Minor code clean ups.