Make the environment reusable

Making the environment variable pass in across both `precompile` and `compile` functions allows other modules to easily extend the behaviour without duplicating large chunks of code.