Reworked environment detection to use the .env files.