Fix segmentation problems