trying to fix the memory leak