Patch for issue #119

I hope this is sufficient to fix #119, and it didn't introduce any new vulnerability.