fix segfaults
Merge pull request #129 from dean-m/master

fix segfaults