Fix variable reassignment issue