fix leaky variable i