fixed memory copy bug