better environment detection