Fix a bug in number of devices detection.