Fix newton calculation, added very basic test for it