Fix remove objects

Fixes #4443, although currently there are problems with unit tests without enabled prototype extensions.