Fix a bug of states not updated on instance removal.
Added a test.
modified test.