Fix variable reassignment bug