Refactor common code.
Add debugging code.
Refactor the UserAgent a bit.