updated legendre and factorization to work with the new dms2