Bugfix when closing and reopening a connection