Refined environment detection