fix env scoping bug