fixed many memory leak bugs