remove some levels of ugly ifs