Fix indices when inserting and deleting elements.