Fix for #20

I recommend applying #18 and #19 first. Once those are done, I'll be happy to rework this pull request.