better gradient
more correct and with bisection