reconnect logic. still some work to be done.
tidying up some stuff