optimised environment detection