Fix segmentation problem for boundaries