Rework reconnection and fix a few other bugs