Added Liang's memory leak fix