Fix a bug of factorize function.