Update get_environment and other improvements.