Extract commonly used code as a base class.