Fix segfault on long strings

Fixes issue #1.