fix events module to detect running environment