Restructure to allow reconnection on connection close