fixed a subtle bug in the garbage collector