use error for return values of functions
fix tests
merged with upstream