write history before dying

TODO - be ready to reconnect rather than dying