Fix null pointer exception with 0 devices