migrate exec function to env, refactor/clarify comments