fixes for potential segmentation faults
Merge pull request #2 from richardtitze/master

fixes for potential segmentation faults