updated factorization code. solution to #3