Factor out the common section into factor() func.