Fix variable reassignment issues