Fix bug where writeItems was happening before an item was deleted.