Replaced detectEnvironment function