newton sqrt refactored