fixed the device checking logic