Fix hanging on Mac OSX

Fixes issue #3.

I'm also working on some test improvements, but I'll open a separate PR for that.