Better error checking on connect/disconnect.