fixed memory leaks.