Environment detection