Moved UserState and ChannelState handling to their own functions to improve readability