Consolidate ifs in where()