Generalize selectability code from 378eae9