Refactor some of the code into a common base class.