move env_open and env_close into their own file, they are too big
Break env_open up into smaller functions