Fix segfault

Fixes issue #52. I hope. Thanks to @AlexMax for raising issue.