Fixed string deallocation and code cleanup
Fixed refcounting bug