Fix add_roots_for()

During investigation of issue #601, @matthiasbeyer found that, apparently, the function `add_roots_for()` misbehaves. Thi PR is aimed at fixing that function.

Note that this PR contains a rewrite of that function. It appears that that rewrite either breaks some functionality or uncovers another bug. I'd suggest investigating whether the other two fixes resolve the issue, e.g. whether the rewrite can be omitted. That would be a job for @matthiasbeyer as he found the original bug.
Is this supposed to be an `if` ? If yes, style fuckup, if not bug!