made some optimization changes to remove_node

It should have speeded up the calculation but instead it slowed it down.
I don't understand
a very small change sped it up again

changing the order of the loop made it 30 percent faster.  cache misses?