Fix issue #1224
Backported pull request #1225
Merge pull request #4 from hintjens/master

Backported fixes from master