Fixed bug in the Q matrix calculation and the univariate factorization function.