refactor duplicated code into a base class