fix memory leak bugs and add ThreadPool