Better connection state tracking
Bug fixes. Add reconnecting