Close connection before exiting