convert to memmove semantics, add more tests
define free function