Generalize the code to handle more than one device per network