Do we need to do all the ifs here? If the environment variable isn't defined it'll come back undefined/falsy, so I'd think you could simplify this by or'ing the various permutations together somehow.