Adding check for null device ID