Improve error handling. Fix bug in optimistic concurrency tests.