fix error handling
Merge remote-tracking branch 'pauldub/master'
Merge pull request #2 from gwik/master

fix error handling infinite loop