fix closure variable overwriting