backport bug fix from 017e86a9ab7c7f4af883fae275dee6e485e0db35

Fixes #22