trying to fix the memory leak problem