removing recursivity in newton_raphson