Fix order of ifs in device filtering.