Bugfix for issue #79

Cherry-picked the commit from my fork, as per #80.