Simplify code by combining ifs.