refactor retrieval of devices