handle errors correctly

fixes #3