Refactor common code to a base class