fixed a few errors in the Newton method, rewrote the matrix.