[Bugfix] Fixed two bugs in CachedElementMap

First bug was a situation where the update() method returned a list of
null elements due to removing and then trying to "replace" the existing
element.

Then fixed a bug where when an element was removed its ID was not
removed the key set.