Prevent error thrown when removing event target

Fixes #1105.