fixed the device_attached function to use the flags structure