fix the timing problem of segmentation fault