Added cstring include, fixed memory leaks