many fixes to reuse a connection and handle all errors