fixed problem when closing a connection