Better cleanup in close_connection()