Add close_environment (finishes #11)