relaxed device selection criterion, plus minor refactoring