Extract environment-forming for macros and lambdas into helper functions, and fix macro scoping