Still struggling with a rather inconsistent segmentation fault