Eofexception

Also, made rollback a bit more robust, so that it will reconnect if
there is an error. And extracted a couple helper methods to cleanup code
This line was moved outside of the `else` block. Intentional?