app: refactor nesting in setEnvs/unsetEnvs