Fix segmentation fault (core dumped) error