added some changes to newton method