Better environment detection