Fixed bugs in channel implementation to handle state.