implement factorize in cython