Fixes issue #46. See the discussion on the issue (I can't add the PR to the issue since I'm not the issue owner).