better error handling
Merge pull request #647 from inc0/errors3

better error handling