minor fixes + overlapping memcpy replaced with memmove