change environment detection method to a closurxible)