Add checks to new code in DeviceManager so that it doesn't try to access null pointers.