Improved reconnection logic