Fix segmentation fault bug