Fix crash when removing device