Fix error handling, detected by integration tests