fix memmove bug and add testing