fixed the memory leak issue with xiaohu's help!