fixed memory leak and crash