Add mem pool and fix the segmentation problem