BUG: fix weight handling in the code that removes redundant nodes