replace free variables in closures with environment lookups