Better error handling in findRoot