changed from malloc to new, and used memcpy.