optimizate compile speed and fix memory leak bugs