Optimize get_roots.