updated detect env name logic