fix various variable copying bugs