Fix variable being reset