Refactored env code into its own submodule and fixed additional errors