use error for return values of functions
fix tests
merged with upstream
Merge pull request #2 from xsleonard/errorhandling

Error handling