Bugfix for issue #76

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