Updated findRoot function.