fixed bug with valid_device matching conditions