Add test for addRemoveItems in PersistentState and fix the discovered bugs.