improved dup_roots_upper_bound

This is the continuation of #7257, with fixed tests.