Re-org some environment variables and code