fixed bug with replaceItemInArray. It seems it is not allowed to delete an element from an array and add another one in the same operation.