Fix variable locality issue