Merge the ifs inside where()