refactor device discovery