Fix to memory leak