Reworked the fix for segmentation fault.