move env_open and env_close into their own file, they are too big