Changed cleanup code because we can reconnect on error