Code snippet for detectEnvironment()

It took me a bit of fiddling to figure out what had changed from L3. I'm hoping this will help others.