Updated the unittest with test for change for both inserting and removing items.
Update cached index correctly for items in array when inserting a new item. Fixes #1892