Thank you so much!! It now rebuilds the hash without gaps and I can delete the first, last or middle images and have it work perfectly. Though I don't see why removing the second foreach did the trick (I only deleted one time), but it works like a charm.