restructure chat to encapsulate all behavior into one component