Don't export variables from case statements

I temporarily used the `warn_export_vars` compile option to spot these. I've also spotted a few areas where we repeat ourselves, but I think it'd be best to tackle that in a separate issue. Or a separate commit on this same branch.