added environment detection