Fixing a ConcurrentModificationException when removing keys