fixed the memory leak