Fix race condition when removing an applet instance