moved matrix factorization code out