Verify write

Coverity flagged a missing write verification before a read, and a wrong error check on failure.

Note: This branch is intentionally based of PR #324 as the function became a callback in that branch.