Fix for #112

Hopefully replacement pull request for @mtravis's #122, which is not
against master