Fixed bug in Newton solver