changed calls to memcpy to memmove