move env vars out of if block