Improved checking for environments