no more memory leaks. final version.