NewtonsMethod implementation