Added environment checking