Collapse nested ifs into a cond