Add error handling around store errors, and fix FD leaking
Fix duff error checking