Added support for setting flags, quitting gracefully, and reseting the environment.