Fix bug with deleting elements

Deleting an element would mess up the order of elements in a grid