Use memmove instead of memcpy for overlapping areas