Rewrite DOOM's replaceChild implementation using existing primitives. This also fixes a couple of issues.