credit for numFactors algorithm