refactoring so common code is not duplicated