First version of newtons method