Reference Error: device is not defined