some typecast and copy fixes