implemented newton method