move common code into a base class