Improve environment variable handling