fixed memory leak bugs