Removed a bug in deregisterdevice