Fixed errors when disconnecting from channels. Resolves #560.