fix closing of connections