Fix memory corruption caused by thoughtless use of memcpy; fixes crash bug