tidy up and handle disconnections cleanly
tidy up and handle disconnections more cleanly