factor common code