fix newtons method and add tests