edited device checking code